@@ -930,7 +930,7 @@ self =>
930
930
case _ => t
931
931
}
932
932
933
- /** Create tree representing (unencoded) binary operation expression or pattern. */
933
+ /** Create tree representing (unencoded) binary operation expression or pattern. Pos set by caller. */
934
934
def makeBinop (isExpr : Boolean , left : Tree , op : TermName , right : Tree , opPos : Position , targs : List [Tree ] = Nil ): Tree = {
935
935
require(isExpr || targs.isEmpty || targs.exists(_.isErroneous),
936
936
s " Incompatible args to makeBinop: !isExpr but targs= $targs" )
@@ -941,42 +941,35 @@ self =>
941
941
val pos = (opPos union t.pos) makeTransparentIf rightAssoc
942
942
val sel = atPos(pos)(Select (stripParens(t), op.encode))
943
943
if (targs.isEmpty) sel
944
- else {
945
- /* if it's right-associative, `targs` are between `op` and `t` so make the pos transparent */
944
+ else
945
+ // if it's right-associative, (deprecated) `targs` are between `op` and `t` so make the pos transparent
946
946
atPos((pos union targs.last.pos) makeTransparentIf rightAssoc) {
947
947
TypeApply (sel, targs)
948
948
}
949
- }
950
949
}
951
950
def mkNamed (args : List [Tree ]) = if (! isExpr) args else
952
951
args.map(treeInfo.assignmentToMaybeNamedArg(_))
953
952
.tap(res => if (currentRun.isScala3 && args.lengthCompare(1 ) == 0 && (args.head ne res.head))
954
953
deprecationWarning(args.head.pos.point, " named argument is deprecated for infix syntax" , since= " 2.13.16" ))
955
954
var isMultiarg = false
956
- val arguments = right match {
955
+ def arguments ( arg : Tree ) = arg match {
957
956
case Parens (Nil ) => literalUnit :: Nil
958
957
case Parens (args @ (_ :: Nil )) => mkNamed(args)
959
958
case Parens (args) => isMultiarg = true ; mkNamed(args)
960
- case _ => right :: Nil
959
+ case _ => arg :: Nil
961
960
}
962
961
def mkApply (fun : Tree , args : List [Tree ]) = {
963
962
val apply = Apply (fun, args).updateAttachment(InfixAttachment )
964
963
if (isMultiarg) apply.updateAttachment(MultiargInfixAttachment )
965
964
apply
966
965
}
967
- if (isExpr) {
968
- if (rightAssoc) {
969
- import symtab .Flags ._
970
- val x = freshTermName(nme.RIGHT_ASSOC_OP_PREFIX )
971
- val liftedArg = atPos(left.pos) {
972
- ValDef (Modifiers (FINAL | SYNTHETIC | ARTIFACT ), x, TypeTree (), stripParens(left))
973
- }
974
- val apply = mkApply(mkSelection(right), List (Ident (x) setPos left.pos.focus))
975
- Block (liftedArg :: Nil , apply)
976
- } else
977
- mkApply(mkSelection(left), arguments)
978
- } else
979
- mkApply(Ident (op.encode), stripParens(left) :: arguments)
966
+ if (isExpr)
967
+ if (rightAssoc)
968
+ mkApply(mkSelection(right), arguments(left)).updateAttachment(RightAssociative )
969
+ else
970
+ mkApply(mkSelection(left), arguments(right))
971
+ else
972
+ mkApply(Ident (op.encode), stripParens(left) :: arguments(right))
980
973
}
981
974
982
975
/** Is current ident a `*`, and is it followed by a `)` or `, )`? */
@@ -1014,10 +1007,9 @@ self =>
1014
1007
}
1015
1008
1016
1009
def checkHeadAssoc (leftAssoc : Boolean ) = checkAssoc(opHead.offset, opHead.operator, leftAssoc)
1017
- def checkAssoc (offset : Offset , op : Name , leftAssoc : Boolean ) = (
1010
+ def checkAssoc (offset : Offset , op : Name , leftAssoc : Boolean ) =
1018
1011
if (nme.isLeftAssoc(op) != leftAssoc)
1019
1012
syntaxError(offset, " left- and right-associative operators with same precedence may not be mixed" , skipIt = false )
1020
- )
1021
1013
1022
1014
def finishPostfixOp (start : Int , base : List [OpInfo ], opinfo : OpInfo ): Tree = {
1023
1015
if (opinfo.targs.nonEmpty)
@@ -1047,7 +1039,7 @@ self =>
1047
1039
1048
1040
def reduceStack (isExpr : Boolean , base : List [OpInfo ], top : Tree ): Tree = {
1049
1041
val opPrecedence = if (isIdent) Precedence (in.name.toString) else Precedence (0 )
1050
- val leftAssoc = ! isIdent || ( nme isLeftAssoc in.name)
1042
+ val leftAssoc = ! isIdent || nme. isLeftAssoc( in.name)
1051
1043
1052
1044
reduceStack(isExpr, base, top, opPrecedence, leftAssoc)
1053
1045
}
0 commit comments