Skip to content

Commit

Permalink
Change inContextBound to a Boolean flag
Browse files Browse the repository at this point in the history
[Cherry-picked ae9cffa]
  • Loading branch information
KacperFKorban authored and WojciechMazur committed Nov 6, 2024
1 parent dac7f7e commit 07583a1
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ object Parsers {
enum IntoOK:
case Yes, No, Nested

enum InContextBound:
case Yes, No

type StageKind = Int
object StageKind {
val None = 0
Expand Down Expand Up @@ -1537,7 +1534,7 @@ object Parsers {
/** Same as [[typ]], but if this results in a wildcard it emits a syntax error and
* returns a tree for type `Any` instead.
*/
def toplevelTyp(intoOK: IntoOK = IntoOK.No, inContextBound: InContextBound = InContextBound.No): Tree =
def toplevelTyp(intoOK: IntoOK = IntoOK.No, inContextBound: Boolean = false): Tree =
rejectWildcardType(typ(intoOK, inContextBound))

private def getFunction(tree: Tree): Option[Function] = tree match {
Expand Down Expand Up @@ -1598,7 +1595,7 @@ object Parsers {
* IntoTargetType ::= Type
* | FunTypeArgs (‘=>’ | ‘?=>’) IntoType
*/
def typ(intoOK: IntoOK = IntoOK.No, inContextBound: InContextBound = InContextBound.No): Tree =
def typ(intoOK: IntoOK = IntoOK.No, inContextBound: Boolean = false): Tree =
val start = in.offset
var imods = Modifiers()
val erasedArgs: ListBuffer[Boolean] = ListBuffer()
Expand Down Expand Up @@ -1831,13 +1828,13 @@ object Parsers {
/** InfixType ::= RefinedType {id [nl] RefinedType}
* | RefinedType `^` // under capture checking
*/
def infixType(inContextBound: InContextBound = InContextBound.No): Tree = infixTypeRest(inContextBound)(refinedType())
def infixType(inContextBound: Boolean = false): Tree = infixTypeRest(inContextBound)(refinedType())

def infixTypeRest(inContextBound: InContextBound = InContextBound.No)(t: Tree, operand: Location => Tree = refinedTypeFn): Tree =
def infixTypeRest(inContextBound: Boolean = false)(t: Tree, operand: Location => Tree = refinedTypeFn): Tree =
infixOps(t, canStartInfixTypeTokens, operand, Location.ElseWhere, ParseKind.Type,
isOperator = !followingIsVararg()
&& !isPureArrow
&& !(isIdent(nme.as) && sourceVersion.isAtLeast(`3.6`) && inContextBound == InContextBound.Yes)
&& !(isIdent(nme.as) && sourceVersion.isAtLeast(`3.6`) && inContextBound)
&& nextCanFollowOperator(canStartInfixTypeTokens))

/** RefinedType ::= WithType {[nl] Refinement} [`^` CaptureSet]
Expand Down Expand Up @@ -2228,7 +2225,7 @@ object Parsers {

/** ContextBound ::= Type [`as` id] */
def contextBound(pname: TypeName): Tree =
val t = toplevelTyp(inContextBound = InContextBound.Yes)
val t = toplevelTyp(inContextBound = true)
val ownName =
if isIdent(nme.as) && sourceVersion.isAtLeast(`3.6`) then
in.nextToken()
Expand Down

0 comments on commit 07583a1

Please sign in to comment.