Skip to content

Commit dfb3b97

Browse files
committed
Drop TreeInfo.isLeftAssoc
Use NameOps#isRightAssocOperatorName instead
1 parent 20d9ccb commit dfb3b97

File tree

7 files changed

+14
-19
lines changed

7 files changed

+14
-19
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ object desugar {
899899
name = mdef.name.toExtensionName,
900900
tparams = ext.tparams ++ mdef.tparams,
901901
vparamss = mdef.vparamss match
902-
case vparams1 :: vparamss1 if !isLeftAssoc(mdef.name) =>
902+
case vparams1 :: vparamss1 if mdef.name.isRightAssocOperatorName =>
903903
vparams1 :: ext.vparamss ::: vparamss1
904904
case _ =>
905905
ext.vparamss ++ mdef.vparamss
@@ -1204,10 +1204,10 @@ object desugar {
12041204
case _ =>
12051205
Apply(sel, arg :: Nil)
12061206

1207-
if (isLeftAssoc(op.name))
1208-
makeOp(left, right, Span(left.span.start, op.span.end, op.span.start))
1209-
else
1207+
if op.name.isRightAssocOperatorName then
12101208
makeOp(right, left, Span(op.span.start, right.span.end))
1209+
else
1210+
makeOp(left, right, Span(left.span.start, op.span.end, op.span.start))
12111211
}
12121212

12131213
/** Translate tuple expressions of arity <= 22

compiler/src/dotty/tools/dotc/ast/Positioned.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Src
208208
check(tree.vparamss)
209209
case tree: DefDef if tree.mods.is(ExtensionMethod) =>
210210
tree.vparamss match {
211-
case vparams1 :: vparams2 :: rest if !isLeftAssoc(tree.name) =>
211+
case vparams1 :: vparams2 :: rest if tree.name.isRightAssocOperatorName =>
212212
check(tree.tparams)
213213
check(vparams2)
214214
check(vparams1)

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,6 @@ trait TreeInfo[T >: Untyped <: Type] { self: Trees.Instance[T] =>
185185
case _ => false
186186
}
187187

188-
/** Is name a left-associative operator? */
189-
def isLeftAssoc(operator: Name): Boolean = !operator.isEmpty && (operator.toSimpleName.last != ':')
190-
191188
/** Is this argument node of the form <expr> : _*, or is it a reference to
192189
* such an argument ? The latter case can happen when an argument is lifted.
193190
*/

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ object Parsers {
927927
var opStack: List[OpInfo] = Nil
928928

929929
def checkAssoc(offset: Token, op1: Name, op2: Name, op2LeftAssoc: Boolean): Unit =
930-
if (isLeftAssoc(op1) != op2LeftAssoc)
930+
if (op1.isRightAssocOperatorName == op2LeftAssoc)
931931
syntaxError(MixedLeftAndRightAssociativeOps(op1, op2, op2LeftAssoc), offset)
932932

933933
def reduceStack(base: List[OpInfo], top: Tree, prec: Int, leftAssoc: Boolean, op2: Name, isType: Boolean): Tree = {
@@ -967,7 +967,7 @@ object Parsers {
967967
def recur(top: Tree): Tree =
968968
if (isIdent && isOperator) {
969969
val op = if (isType) typeIdent() else termIdent()
970-
val top1 = reduceStack(base, top, precedence(op.name), isLeftAssoc(op.name), op.name, isType)
970+
val top1 = reduceStack(base, top, precedence(op.name), !op.name.isRightAssocOperatorName, op.name, isType)
971971
opStack = OpInfo(top1, op, in.offset) :: opStack
972972
colonAtEOLOpt()
973973
newLineOptWhenFollowing(canStartOperand)
@@ -3316,7 +3316,7 @@ object Parsers {
33163316
typeParamClause(ParamOwner.Def)
33173317
else leadingTparams
33183318
val vparamss = paramClauses() match
3319-
case rparams :: rparamss if leadingVparamss.nonEmpty && !isLeftAssoc(ident.name) =>
3319+
case rparams :: rparamss if leadingVparamss.nonEmpty && ident.name.isRightAssocOperatorName =>
33203320
rparams :: leadingVparamss ::: rparamss
33213321
case rparamss =>
33223322
leadingVparamss ::: rparamss

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
795795
val (prefix, vparamss) =
796796
if isExtension then
797797
val (leadingParams, otherParamss) = (tree.vparamss: @unchecked) match
798-
case vparams1 :: vparams2 :: rest if !isLeftAssoc(tree.name) =>
798+
case vparams1 :: vparams2 :: rest if tree.name.isRightAssocOperatorName =>
799799
(vparams2, vparams1 :: rest)
800800
case vparams1 :: rest =>
801801
(vparams1, rest)

compiler/src/dotty/tools/dotc/typer/RefChecks.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1620,7 +1620,7 @@ class RefChecks extends MiniPhase { thisPhase =>
16201620
private def checkByNameRightAssociativeDef(tree: DefDef) {
16211621
tree match {
16221622
case DefDef(_, name, _, params :: _, _, _) =>
1623-
if (settings.lint && !treeInfo.isLeftAssoc(name.decodedName) && params.exists(p => isByName(p.symbol)))
1623+
if (settings.lint && name.decodedName.isRightAssocOperatorName && params.exists(p => isByName(p.symbol)))
16241624
unit.warning(tree.pos,
16251625
"by-name parameters will be evaluated eagerly when called as a right-associative infix operator. For more details, see SI-1980.")
16261626
case _ =>

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ class Typer extends Namer
446446
// cyclic references.
447447
if (name == nme.ROOTPKG)
448448
return tree.withType(defn.RootPackage.termRef)
449-
449+
450450
val rawType = {
451451
val saved1 = unimported
452452
val saved2 = foundUnderScala2
@@ -2342,20 +2342,18 @@ class Typer extends Namer
23422342
typedUnApply(cpy.Apply(tree)(op, l :: r :: Nil), pt)
23432343
else {
23442344
val app = typedApply(desugar.binop(l, op, r), pt)
2345-
if (untpd.isLeftAssoc(op.name)) app
2346-
else {
2345+
if op.name.isRightAssocOperatorName then
23472346
val defs = new mutable.ListBuffer[Tree]
2348-
def lift(app: Tree): Tree = (app: @unchecked) match {
2347+
def lift(app: Tree): Tree = (app: @unchecked) match
23492348
case Apply(fn, args) =>
23502349
if (app.tpe.isError) app
23512350
else tpd.cpy.Apply(app)(fn, LiftImpure.liftArgs(defs, fn.tpe, args))
23522351
case Assign(lhs, rhs) =>
23532352
tpd.cpy.Assign(app)(lhs, lift(rhs))
23542353
case Block(stats, expr) =>
23552354
tpd.cpy.Block(app)(stats, lift(expr))
2356-
}
23572355
wrapDefs(defs, lift(app))
2358-
}
2356+
else app
23592357
}
23602358
checkValidInfix(tree, result.symbol)
23612359
result

0 commit comments

Comments
 (0)