@@ -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
@@ -1534,7 +1537,8 @@ object Parsers {
1534
1537
/** Same as [[typ ]], but if this results in a wildcard it emits a syntax error and
1535
1538
* returns a tree for type `Any` instead.
1536
1539
*/
1537
- def toplevelTyp (intoOK : IntoOK = IntoOK .No ): Tree = rejectWildcardType(typ(intoOK))
1540
+ def toplevelTyp (intoOK : IntoOK = IntoOK .No , inContextBound : InContextBound = InContextBound .No ): Tree =
1541
+ rejectWildcardType(typ(intoOK, inContextBound))
1538
1542
1539
1543
private def getFunction (tree : Tree ): Option [Function ] = tree match {
1540
1544
case Parens (tree1) => getFunction(tree1)
@@ -1594,7 +1598,7 @@ object Parsers {
1594
1598
* IntoTargetType ::= Type
1595
1599
* | FunTypeArgs (‘=>’ | ‘?=>’) IntoType
1596
1600
*/
1597
- def typ (intoOK : IntoOK = IntoOK .No ): Tree =
1601
+ def typ (intoOK : IntoOK = IntoOK .No , inContextBound : InContextBound = InContextBound . No ): Tree =
1598
1602
val start = in.offset
1599
1603
var imods = Modifiers ()
1600
1604
val erasedArgs : ListBuffer [Boolean ] = ListBuffer ()
@@ -1743,7 +1747,7 @@ object Parsers {
1743
1747
val tuple = atSpan(start):
1744
1748
makeTupleOrParens(args.mapConserve(convertToElem))
1745
1749
typeRest :
1746
- infixTypeRest :
1750
+ infixTypeRest(inContextBound) :
1747
1751
refinedTypeRest :
1748
1752
withTypeRest :
1749
1753
annotTypeRest :
@@ -1772,7 +1776,7 @@ object Parsers {
1772
1776
else if isIntoPrefix then
1773
1777
PrefixOp (typeIdent(), typ(IntoOK .Nested ))
1774
1778
else
1775
- typeRest(infixType())
1779
+ typeRest(infixType(inContextBound ))
1776
1780
end typ
1777
1781
1778
1782
private def makeKindProjectorTypeDef (name : TypeName ): TypeDef = {
@@ -1827,13 +1831,13 @@ object Parsers {
1827
1831
/** InfixType ::= RefinedType {id [nl] RefinedType}
1828
1832
* | RefinedType `^` // under capture checking
1829
1833
*/
1830
- def infixType (): Tree = infixTypeRest(refinedType())
1834
+ def infixType (inContextBound : InContextBound = InContextBound . No ): Tree = infixTypeRest(inContextBound) (refinedType())
1831
1835
1832
- def infixTypeRest (t : Tree , operand : Location => Tree = refinedTypeFn): Tree =
1836
+ def infixTypeRest (inContextBound : InContextBound = InContextBound . No )( t : Tree , operand : Location => Tree = refinedTypeFn): Tree =
1833
1837
infixOps(t, canStartInfixTypeTokens, operand, Location .ElseWhere , ParseKind .Type ,
1834
1838
isOperator = ! followingIsVararg()
1835
1839
&& ! isPureArrow
1836
- && ! (isIdent(nme.as) && sourceVersion.isAtLeast(`3.6`))
1840
+ && ! (isIdent(nme.as) && sourceVersion.isAtLeast(`3.6`) && inContextBound == InContextBound . Yes )
1837
1841
&& nextCanFollowOperator(canStartInfixTypeTokens))
1838
1842
1839
1843
/** RefinedType ::= WithType {[nl] Refinement} [`^` CaptureSet]
@@ -2224,7 +2228,7 @@ object Parsers {
2224
2228
2225
2229
/** ContextBound ::= Type [`as` id] */
2226
2230
def contextBound (pname : TypeName ): Tree =
2227
- val t = toplevelTyp()
2231
+ val t = toplevelTyp(inContextBound = InContextBound . Yes )
2228
2232
val ownName =
2229
2233
if isIdent(nme.as) && sourceVersion.isAtLeast(`3.6`) then
2230
2234
in.nextToken()
@@ -4209,7 +4213,7 @@ object Parsers {
4209
4213
else constrApp() match
4210
4214
case parent : Apply => parent :: moreConstrApps()
4211
4215
case parent if in.isIdent && newSyntaxAllowed =>
4212
- infixTypeRest(parent, _ => annotType1()) :: Nil
4216
+ infixTypeRest()( parent, _ => annotType1()) :: Nil
4213
4217
case parent => parent :: moreConstrApps()
4214
4218
4215
4219
// The term parameters and parent references */
0 commit comments