@@ -1636,6 +1636,7 @@ object Parsers {
1636
1636
* | TypTypeParamClause ‘=>>’ Type
1637
1637
* | FunParamClause ‘=>>’ Type
1638
1638
* | MatchType
1639
+ * | QualifiedType2 -- under qualifiedTypes
1639
1640
* | InfixType
1640
1641
* FunType ::= (MonoFunType | PolyFunType)
1641
1642
* MonoFunType ::= FunTypeArgs (‘=>’ | ‘?=>’) Type
@@ -1646,6 +1647,11 @@ object Parsers {
1646
1647
* | `(' [ FunArgType {`,' FunArgType } ] `)'
1647
1648
* | '(' [ TypedFunParam {',' TypedFunParam } ')'
1648
1649
* MatchType ::= InfixType `match` <<< TypeCaseClauses >>>
1650
+ * QualifiedType2 ::= InfixType `with` PostfixExprf
1651
+ * IntoType ::= [‘into’] IntoTargetType
1652
+ * | ‘( IntoType ‘)’
1653
+ * IntoTargetType ::= Type
1654
+ * | FunTypeArgs (‘=>’ | ‘?=>’) IntoType
1649
1655
*/
1650
1656
def typ (inContextBound : Boolean = false ): Tree =
1651
1657
val start = in.offset
@@ -1705,6 +1711,8 @@ object Parsers {
1705
1711
functionRest(t :: Nil )
1706
1712
case MATCH =>
1707
1713
matchType(t)
1714
+ case WITH if in.featureEnabled(Feature .qualifiedTypes) =>
1715
+ qualifiedTypeShort(t)
1708
1716
case FORSOME =>
1709
1717
syntaxError(ExistentialTypesNoLongerSupported ())
1710
1718
t
@@ -1839,6 +1847,7 @@ object Parsers {
1839
1847
def funParamClauses (): List [List [ValDef ]] =
1840
1848
if in.token == LPAREN then funParamClause() :: funParamClauses() else Nil
1841
1849
1850
+
1842
1851
/** InfixType ::= RefinedType {id [nl] RefinedType}
1843
1852
* | RefinedType `^` -- under captureChecking
1844
1853
*/
@@ -1893,22 +1902,12 @@ object Parsers {
1893
1902
t
1894
1903
}
1895
1904
1896
- /** With qualifiedTypes enabled:
1897
- * WithType ::= AnnotType [`with' PostfixExpr]
1898
- *
1899
- * Otherwise:
1900
- * WithType ::= AnnotType {`with' AnnotType} (deprecated)
1901
- */
1905
+ /** WithType ::= AnnotType {`with' AnnotType} (deprecated)
1906
+ */
1902
1907
def withType (): Tree = withTypeRest(annotType())
1903
1908
1904
1909
def withTypeRest (t : Tree ): Tree =
1905
- if in.featureEnabled(Feature .qualifiedTypes) && in.token == WITH then
1906
- if inQualifiedType then t
1907
- else
1908
- in.nextToken()
1909
- val qualifier = postfixExpr()
1910
- QualifiedTypeTree (t, None , qualifier).withSpan(Span (t.span.start, qualifier.span.end))
1911
- else if in.token == WITH then
1910
+ if in.token == WITH && ! in.featureEnabled(Feature .qualifiedTypes) then
1912
1911
val withOffset = in.offset
1913
1912
in.nextToken()
1914
1913
if in.token == LBRACE || in.token == INDENT then
@@ -2247,6 +2246,17 @@ object Parsers {
2247
2246
accept(RBRACE )
2248
2247
QualifiedTypeTree (tp, Some (id), qualifier).withSpan(Span (startOffset, qualifier.span.end))
2249
2248
2249
+ /** `with` PostfixExpr
2250
+ */
2251
+ def qualifiedTypeShort (t : Tree ): Tree =
2252
+ if inQualifiedType then
2253
+ t
2254
+ else
2255
+ accept(WITH )
2256
+ val qualifier = postfixExpr()
2257
+ QualifiedTypeTree (t, None , qualifier).withSpan(Span (t.span.start, qualifier.span.end))
2258
+
2259
+
2250
2260
/** TypeBounds ::= [`>:' TypeBound ] [`<:' TypeBound ]
2251
2261
* TypeBound ::= Type
2252
2262
* | CaptureSet -- under captureChecking
@@ -2323,7 +2333,12 @@ object Parsers {
2323
2333
2324
2334
def typeDependingOn (location : Location ): Tree =
2325
2335
if location.inParens then typ()
2326
- else if location.inPattern then rejectWildcardType(refinedType())
2336
+ else if location.inPattern then
2337
+ val t = rejectWildcardType(refinedType())
2338
+ if in.featureEnabled(Feature .qualifiedTypes) && in.token == WITH then
2339
+ qualifiedTypeShort(t)
2340
+ else
2341
+ t
2327
2342
else infixType()
2328
2343
2329
2344
/* ----------- EXPRESSIONS ------------------------------------------------ */
@@ -3165,10 +3180,11 @@ object Parsers {
3165
3180
if (isIdent(nme.raw.BAR )) { in.nextToken(); pattern1(location) :: patternAlts(location) }
3166
3181
else Nil
3167
3182
3168
- /** Pattern1 ::= PatVar `:` RefinedType
3169
- * | [‘-’] integerLiteral `:` RefinedType
3170
- * | [‘-’] floatingPointLiteral `:` RefinedType
3171
- * | Pattern2
3183
+ /** Pattern1 ::= PatVar `:` QualifiedType3
3184
+ * | [‘-’] integerLiteral `:` QualifiedType3
3185
+ * | [‘-’] floatingPointLiteral `:` QualifiedType3
3186
+ * | Pattern2
3187
+ * QualifiedType3 ::= RefinedType [`with` PostfixExpr]
3172
3188
*/
3173
3189
def pattern1 (location : Location = Location .InPattern ): Tree =
3174
3190
val p = pattern2(location)
0 commit comments