Skip to content

Commit de8eb4d

Browse files
committed
Hardcode SIP-33: term and type operators have the same priority
1 parent dfdf9a1 commit de8eb4d

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,13 +471,13 @@ object Parsers {
471471
syntaxError(MixedLeftAndRightAssociativeOps(op1, op2, op2LeftAssoc), offset)
472472

473473
def reduceStack(base: List[OpInfo], top: Tree, prec: Int, leftAssoc: Boolean, op2: Name, isType: Boolean): Tree = {
474-
if (opStack != base && precedence(opStack.head.operator.name, isType) == prec)
474+
if (opStack != base && precedence(opStack.head.operator.name) == prec)
475475
checkAssoc(opStack.head.offset, opStack.head.operator.name, op2, leftAssoc)
476476
def recur(top: Tree): Tree = {
477477
if (opStack == base) top
478478
else {
479479
val opInfo = opStack.head
480-
val opPrec = precedence(opInfo.operator.name, isType)
480+
val opPrec = precedence(opInfo.operator.name)
481481
if (prec < opPrec || leftAssoc && prec == opPrec) {
482482
opStack = opStack.tail
483483
recur {
@@ -514,7 +514,7 @@ object Parsers {
514514
var top = first
515515
while (isIdent && isOperator) {
516516
val op = if (isType) typeIdent() else termIdent()
517-
top = reduceStack(base, top, precedence(op.name, isType), isLeftAssoc(op.name), op.name, isType)
517+
top = reduceStack(base, top, precedence(op.name), isLeftAssoc(op.name), op.name, isType)
518518
opStack = OpInfo(top, op, in.offset) :: opStack
519519
newLineOptWhenFollowing(canStartOperand)
520520
if (maybePostfix && !canStartOperand(in.token)) {

compiler/src/dotty/tools/dotc/parsing/package.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import core.NameOps._
77

88
package object parsing {
99

10-
def precedence(operator: Name, isType: Boolean = false): Int =
10+
def precedence(operator: Name): Int =
1111
if (operator eq nme.ERROR) -1
1212
else {
1313
val firstCh = operator.firstPart.head

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
165165

166166
def toTextInfixType(opName: Name, l: Type, r: Type)(op: => Text): Text = {
167167
val isRightAssoc = opName.endsWith(":")
168-
val opPrec = parsing.precedence(opName, true)
168+
val opPrec = parsing.precedence(opName)
169169

170170
changePrec(opPrec) {
171171
val leftPrec = if (isRightAssoc || checkAssocMismatch(l, isRightAssoc)) opPrec + 1 else opPrec

compiler/src/dotty/tools/dotc/printing/package.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ package object printing {
99
type Precedence = Int
1010

1111
val DotPrec = parsing.maxPrec
12-
val AndTypePrec = parsing.precedence(tpnme.raw.AMP, true)
13-
val OrTypePrec = parsing.precedence(tpnme.raw.BAR, true)
12+
val AndTypePrec = parsing.precedence(tpnme.raw.AMP)
13+
val OrTypePrec = parsing.precedence(tpnme.raw.BAR)
1414
val OrPrec = parsing.precedence(nme.raw.BAR)
1515
val InfixPrec = parsing.minInfixPrec
1616
val GlobalPrec = parsing.minPrec

0 commit comments

Comments
 (0)