@@ -80,6 +80,9 @@ object Parsers {
80
80
enum IntoOK :
81
81
case Yes , No , Nested
82
82
83
+ enum InContextBound :
84
+ case Yes , No
85
+
83
86
type StageKind = Int
84
87
object StageKind {
85
88
val None = 0
@@ -1550,7 +1553,8 @@ object Parsers {
1550
1553
/** Same as [[typ ]], but if this results in a wildcard it emits a syntax error and
1551
1554
* returns a tree for type `Any` instead.
1552
1555
*/
1553
- def toplevelTyp (intoOK : IntoOK = IntoOK .No ): Tree = rejectWildcardType(typ(intoOK))
1556
+ def toplevelTyp (intoOK : IntoOK = IntoOK .No , inContextBound : InContextBound = InContextBound .No ): Tree =
1557
+ rejectWildcardType(typ(intoOK, inContextBound))
1554
1558
1555
1559
private def getFunction (tree : Tree ): Option [Function ] = tree match {
1556
1560
case Parens (tree1) => getFunction(tree1)
@@ -1605,7 +1609,7 @@ object Parsers {
1605
1609
* IntoTargetType ::= Type
1606
1610
* | FunTypeArgs (‘=>’ | ‘?=>’) IntoType
1607
1611
*/
1608
- def typ (intoOK : IntoOK = IntoOK .No ): Tree =
1612
+ def typ (intoOK : IntoOK = IntoOK .No , inContextBound : InContextBound = InContextBound . No ): Tree =
1609
1613
val start = in.offset
1610
1614
var imods = Modifiers ()
1611
1615
val erasedArgs : ListBuffer [Boolean ] = ListBuffer ()
@@ -1754,7 +1758,7 @@ object Parsers {
1754
1758
val tuple = atSpan(start):
1755
1759
makeTupleOrParens(args.mapConserve(convertToElem))
1756
1760
typeRest :
1757
- infixTypeRest :
1761
+ infixTypeRest(inContextBound) :
1758
1762
refinedTypeRest :
1759
1763
withTypeRest :
1760
1764
annotTypeRest :
@@ -1777,7 +1781,7 @@ object Parsers {
1777
1781
else if isIntoPrefix then
1778
1782
PrefixOp (typeIdent(), typ(IntoOK .Nested ))
1779
1783
else
1780
- typeRest(infixType())
1784
+ typeRest(infixType(inContextBound ))
1781
1785
end typ
1782
1786
1783
1787
private def makeKindProjectorTypeDef (name : TypeName ): TypeDef = {
@@ -1832,13 +1836,13 @@ object Parsers {
1832
1836
/** InfixType ::= RefinedType {id [nl] RefinedType}
1833
1837
* | RefinedType `^` // under capture checking
1834
1838
*/
1835
- def infixType (): Tree = infixTypeRest(refinedType())
1839
+ def infixType (inContextBound : InContextBound = InContextBound . No ): Tree = infixTypeRest(inContextBound) (refinedType())
1836
1840
1837
- def infixTypeRest (t : Tree , operand : Location => Tree = refinedTypeFn): Tree =
1841
+ def infixTypeRest (inContextBound : InContextBound = InContextBound . No )( t : Tree , operand : Location => Tree = refinedTypeFn): Tree =
1838
1842
infixOps(t, canStartInfixTypeTokens, operand, Location .ElseWhere , ParseKind .Type ,
1839
1843
isOperator = ! followingIsVararg()
1840
1844
&& ! isPureArrow
1841
- && ! (isIdent(nme.as) && sourceVersion.isAtLeast(`3.6`))
1845
+ && ! (isIdent(nme.as) && sourceVersion.isAtLeast(`3.6`) && inContextBound == InContextBound . Yes )
1842
1846
&& nextCanFollowOperator(canStartInfixTypeTokens))
1843
1847
1844
1848
/** RefinedType ::= WithType {[nl] Refinement} [`^` CaptureSet]
@@ -2229,7 +2233,7 @@ object Parsers {
2229
2233
2230
2234
/** ContextBound ::= Type [`as` id] */
2231
2235
def contextBound (pname : TypeName ): Tree =
2232
- val t = toplevelTyp()
2236
+ val t = toplevelTyp(inContextBound = InContextBound . Yes )
2233
2237
val ownName =
2234
2238
if isIdent(nme.as) && sourceVersion.isAtLeast(`3.6`) then
2235
2239
in.nextToken()
@@ -4207,7 +4211,7 @@ object Parsers {
4207
4211
else constrApp() match
4208
4212
case parent : Apply => parent :: moreConstrApps()
4209
4213
case parent if in.isIdent && newSyntaxAllowed =>
4210
- infixTypeRest(parent, _ => annotType1()) :: Nil
4214
+ infixTypeRest()( parent, _ => annotType1()) :: Nil
4211
4215
case parent => parent :: moreConstrApps()
4212
4216
4213
4217
// The term parameters and parent references */
0 commit comments