@@ -46,11 +46,6 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
46
46
47
47
final val shortenImports = false
48
48
49
- // All typechecked RHS of ValDefs for right-associative operator desugaring
50
- private val rightAssocValDefs = new mutable.AnyRefMap [Symbol , Tree ]
51
- // Symbols of ValDefs for right-associative operator desugaring which are passed by name and have been inlined
52
- private val inlinedRightAssocValDefs = new mutable.HashSet [Symbol ]
53
-
54
49
// For each class, we collect a mapping from constructor param accessors that are aliases of their superclass
55
50
// param accessors. At the end of the typer phase, when this information is available all the way up the superclass
56
51
// chain, this is used to determine which are true aliases, ones where the field can be elided from this class.
@@ -66,8 +61,6 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
66
61
resetContexts()
67
62
resetImplicits()
68
63
resetDocComments()
69
- rightAssocValDefs.clear()
70
- inlinedRightAssocValDefs.clear()
71
64
superConstructorCalls.clear()
72
65
}
73
66
@@ -2143,10 +2136,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
2143
2136
} else tpt1.tpe
2144
2137
transformedOrTyped(vdef.rhs, EXPRmode | BYVALmode , tpt2)
2145
2138
}
2146
- val vdef1 = treeCopy.ValDef (vdef, typedMods, sym.name, tpt1, checkDead(context, rhs1)) setType NoType
2147
- if (sym.isSynthetic && sym.name.startsWith(nme.RIGHT_ASSOC_OP_PREFIX ))
2148
- rightAssocValDefs += ((sym, vdef1.rhs))
2149
- vdef1
2139
+ treeCopy.ValDef (vdef, typedMods, sym.name, tpt1, checkDead(context, rhs1)) setType NoType
2150
2140
}
2151
2141
2152
2142
/** Analyze the super constructor call to record information used later to compute parameter aliases */
@@ -2559,13 +2549,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
2559
2549
if (result0.nonEmpty) checkPure(result0, supple = true )
2560
2550
}
2561
2551
2562
- // Remove ValDef for right-associative by-value operator desugaring which has been inlined into expr1
2563
- val statsTyped2 = statsTyped match {
2564
- case (vd : ValDef ) :: Nil if inlinedRightAssocValDefs.remove(vd.symbol) => Nil
2565
- case _ => statsTyped
2566
- }
2567
-
2568
- treeCopy.Block (block, statsTyped2, expr1)
2552
+ treeCopy.Block (block, statsTyped, expr1)
2569
2553
.setType(if (treeInfo.isExprSafeToInline(block)) expr1.tpe else expr1.tpe.deconst)
2570
2554
} finally {
2571
2555
// enable escaping privates checking from the outside and recycle
@@ -3727,29 +3711,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
3727
3711
case _ => tp
3728
3712
}
3729
3713
3730
- // Inline RHS of ValDef for right-associative by-value operator desugaring.
3731
- // Remove the ValDef also if the argument is a constant-folded reference to it.
3732
3714
var (args2, pos2) = (args1, tree.pos)
3733
- args1 match {
3734
- case List (lit : Literal ) =>
3735
- lit.attachments.get[OriginalTreeAttachment ] match {
3736
- case Some (OriginalTreeAttachment (id : Ident )) if rightAssocValDefs.contains(id.symbol) =>
3737
- inlinedRightAssocValDefs += id.symbol
3738
- rightAssocValDefs.remove(id.symbol)
3739
- case _ =>
3740
- }
3741
-
3742
- case List (id : Ident ) if rightAssocValDefs.contains(id.symbol) =>
3743
- mt.params match {
3744
- case List (p) if p.isByNameParam =>
3745
- inlinedRightAssocValDefs += id.symbol
3746
- val rhs = rightAssocValDefs.remove(id.symbol).get
3747
- args2 = rhs.changeOwner(id.symbol -> context.owner) :: Nil
3748
- pos2 = wrappingPos(tree :: rhs :: Nil )
3749
- case _ =>
3750
- }
3751
- case _ =>
3752
- }
3753
3715
3754
3716
if (args.isEmpty && canTranslateEmptyListToNil && fun.symbol.isInitialized && currentRun.runDefinitions.isListApply(fun))
3755
3717
atPos(tree.pos)(gen.mkNil setType restpe)
@@ -4928,7 +4890,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
4928
4890
}
4929
4891
}
4930
4892
4931
- def typedApply (tree : Apply ) = tree match {
4893
+ def typedApply (tree : Apply ): Tree = tree match {
4932
4894
case Apply (Block (stats, expr), args) =>
4933
4895
typed1(atPos(tree.pos)(Block (stats, Apply (expr, args) setPos tree.pos.makeTransparent)), mode, pt)
4934
4896
case Apply (fun, args) =>
@@ -4952,7 +4914,24 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
4952
4914
// The enclosing context may be case c @ C(_) => or val c @ C(_) = v.
4953
4915
tree1 modifyType (_.finalResultType)
4954
4916
tree1
4955
- case tree1 => tree1
4917
+ case tree1 @ Apply (fun1, arg1 :: Nil ) if tree.hasAttachment[RightAssociative .type ] =>
4918
+ fun1.tpe match {
4919
+ // fix evaluation order of `x op_: y` if necessary to `{ val tmp = x ; y.op_:(tmp) }`
4920
+ case MethodType (p :: Nil , _) if ! tree1.isErroneous && ! p.isByNameParam && (! treeInfo.isStableIdentifier(arg1, allowVolatile = false ) || ! treeInfo.isExprSafeToInline(arg1)) =>
4921
+ import symtab .Flags ._
4922
+ val tmp = freshTermName(nme.RIGHT_ASSOC_OP_PREFIX )
4923
+ val valSym = context.owner.newValue(tmp, arg1.pos.focus, FINAL | SYNTHETIC | ARTIFACT )
4924
+ val rhs = arg1.changeOwner(context.owner -> valSym)
4925
+ valSym.setInfo(rhs.tpe)
4926
+ val liftedArg = atPos(arg1.pos) { ValDef (valSym, rhs) }
4927
+ val blk = Block (
4928
+ liftedArg :: Nil ,
4929
+ treeCopy.Apply (tree1, fun1, List (Ident (valSym) setPos arg1.pos.focus)).clearType()
4930
+ )
4931
+ typed(blk, mode, pt)
4932
+ case _ => tree1
4933
+ }
4934
+ case tree1 => tree1
4956
4935
}
4957
4936
}
4958
4937
0 commit comments