@@ -47,11 +47,6 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
47
47
48
48
final val shortenImports = false
49
49
50
- // All typechecked RHS of ValDefs for right-associative operator desugaring
51
- private val rightAssocValDefs = new mutable.AnyRefMap [Symbol , Tree ]
52
- // Symbols of ValDefs for right-associative operator desugaring which are passed by name and have been inlined
53
- private val inlinedRightAssocValDefs = new mutable.HashSet [Symbol ]
54
-
55
50
// For each class, we collect a mapping from constructor param accessors that are aliases of their superclass
56
51
// param accessors. At the end of the typer phase, when this information is available all the way up the superclass
57
52
// chain, this is used to determine which are true aliases, ones where the field can be elided from this class.
@@ -67,8 +62,6 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
67
62
resetContexts()
68
63
resetImplicits()
69
64
resetDocComments()
70
- rightAssocValDefs.clear()
71
- inlinedRightAssocValDefs.clear()
72
65
superConstructorCalls.clear()
73
66
}
74
67
@@ -2164,10 +2157,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
2164
2157
} else tpt1.tpe
2165
2158
transformedOrTyped(vdef.rhs, EXPRmode | BYVALmode , tpt2)
2166
2159
}
2167
- val vdef1 = treeCopy.ValDef (vdef, typedMods, sym.name, tpt1, checkDead(context, rhs1)) setType NoType
2168
- if (sym.isSynthetic && sym.name.startsWith(nme.RIGHT_ASSOC_OP_PREFIX ))
2169
- rightAssocValDefs += ((sym, vdef1.rhs))
2170
- vdef1
2160
+ treeCopy.ValDef (vdef, typedMods, sym.name, tpt1, checkDead(context, rhs1)) setType NoType
2171
2161
}
2172
2162
2173
2163
/** Analyze the super constructor call to record information used later to compute parameter aliases */
@@ -2587,13 +2577,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
2587
2577
if (isMultiline && settings.warnByNameImplicit) checkImplicitlyAdaptedBlockResult(expr1)
2588
2578
}
2589
2579
2590
- // Remove ValDef for right-associative by-value operator desugaring which has been inlined into expr1
2591
- val statsTyped2 = statsTyped match {
2592
- case (vd : ValDef ) :: Nil if inlinedRightAssocValDefs.remove(vd.symbol) => Nil
2593
- case _ => statsTyped
2594
- }
2595
-
2596
- treeCopy.Block (block, statsTyped2, expr1)
2580
+ treeCopy.Block (block, statsTyped, expr1)
2597
2581
.setType(if (treeInfo.isExprSafeToInline(block)) expr1.tpe else expr1.tpe.deconst)
2598
2582
} finally {
2599
2583
// enable escaping privates checking from the outside and recycle
@@ -3778,29 +3762,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
3778
3762
case _ => tp
3779
3763
}
3780
3764
3781
- // Inline RHS of ValDef for right-associative by-value operator desugaring.
3782
- // Remove the ValDef also if the argument is a constant-folded reference to it.
3783
3765
var (args2, pos2) = (args1, tree.pos)
3784
- args1 match {
3785
- case List (lit : Literal ) =>
3786
- lit.attachments.get[OriginalTreeAttachment ] match {
3787
- case Some (OriginalTreeAttachment (id : Ident )) if rightAssocValDefs.contains(id.symbol) =>
3788
- inlinedRightAssocValDefs += id.symbol
3789
- rightAssocValDefs.remove(id.symbol)
3790
- case _ =>
3791
- }
3792
-
3793
- case List (id : Ident ) if rightAssocValDefs.contains(id.symbol) =>
3794
- mt.params match {
3795
- case List (p) if p.isByNameParam =>
3796
- inlinedRightAssocValDefs += id.symbol
3797
- val rhs = rightAssocValDefs.remove(id.symbol).get
3798
- args2 = rhs.changeOwner(id.symbol -> context.owner) :: Nil
3799
- pos2 = wrappingPos(tree :: rhs :: Nil )
3800
- case _ =>
3801
- }
3802
- case _ =>
3803
- }
3804
3766
3805
3767
if (args.isEmpty && canTranslateEmptyListToNil && fun.symbol.isInitialized && currentRun.runDefinitions.isListApply(fun))
3806
3768
atPos(tree.pos)(gen.mkNil setType restpe)
@@ -5028,7 +4990,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
5028
4990
}
5029
4991
}
5030
4992
5031
- def typedApply (tree : Apply ) = tree match {
4993
+ def typedApply (tree : Apply ): Tree = tree match {
5032
4994
case Apply (Block (stats, expr), args) =>
5033
4995
typed1(atPos(tree.pos)(Block (stats, Apply (expr, args) setPos tree.pos.makeTransparent)), mode, pt)
5034
4996
case Apply (fun, args) =>
@@ -5052,7 +5014,24 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
5052
5014
// The enclosing context may be case c @ C(_) => or val c @ C(_) = v.
5053
5015
tree1 modifyType (_.finalResultType)
5054
5016
tree1
5055
- case tree1 => tree1
5017
+ case tree1 @ Apply (fun1, arg1 :: Nil ) if tree.hasAttachment[RightAssociative .type ] =>
5018
+ fun1.tpe match {
5019
+ // fix evaluation order of `x op_: y` if necessary to `{ val tmp = x ; y.op_:(tmp) }`
5020
+ case MethodType (p :: Nil , _) if ! tree1.isErroneous && ! p.isByNameParam && (! treeInfo.isStableIdentifier(arg1, allowVolatile = false ) || ! treeInfo.isExprSafeToInline(arg1)) =>
5021
+ import symtab .Flags ._
5022
+ val tmp = freshTermName(nme.RIGHT_ASSOC_OP_PREFIX )
5023
+ val valSym = context.owner.newValue(tmp, arg1.pos.focus, FINAL | SYNTHETIC | ARTIFACT )
5024
+ val rhs = arg1.changeOwner(context.owner -> valSym)
5025
+ valSym.setInfo(rhs.tpe)
5026
+ val liftedArg = atPos(arg1.pos) { ValDef (valSym, rhs) }
5027
+ val blk = Block (
5028
+ liftedArg :: Nil ,
5029
+ treeCopy.Apply (tree1, fun1, List (Ident (valSym) setPos arg1.pos.focus)).clearType()
5030
+ )
5031
+ typed(blk, mode, pt)
5032
+ case _ => tree1
5033
+ }
5034
+ case tree1 => tree1
5056
5035
}
5057
5036
}
5058
5037
0 commit comments