Skip to content

Commit a604fb5

Browse files
committed
Address review comments
1 parent 01b7ce5 commit a604fb5

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

src/compiler/scala/tools/nsc/typechecker/Typers.scala

+5-5
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
4545
final val shortenImports = false
4646

4747
// All typechecked RHS of ValDefs for right-associative operator desugaring
48-
val rightAssocValDefs = new mutable.AnyRefMap[Symbol, Tree]
48+
private val rightAssocValDefs = new mutable.AnyRefMap[Symbol, Tree]
4949
// Symbols of ValDefs for right-associative operator desugaring which are passed by name and have been inlined
50-
val inlinedRightAssocValDefs = new mutable.HashSet[Symbol]
50+
private val inlinedRightAssocValDefs = new mutable.HashSet[Symbol]
5151

5252
// allows override of the behavior of the resetTyper method w.r.t comments
5353
def resetDocComments() = {
@@ -2071,7 +2071,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
20712071
transformedOrTyped(vdef.rhs, EXPRmode | BYVALmode, tpt2)
20722072
}
20732073
val vdef1 = treeCopy.ValDef(vdef, typedMods, sym.name, tpt1, checkDead(rhs1)) setType NoType
2074-
if (sym.isSynthetic && sym.name.toString.startsWith(nme.RIGHT_ASSOC_OP_PREFIX))
2074+
if (sym.isSynthetic && sym.name.startsWith(nme.RIGHT_ASSOC_OP_PREFIX))
20752075
rightAssocValDefs += ((sym, vdef1.rhs))
20762076
vdef1
20772077
}
@@ -2486,7 +2486,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
24862486

24872487
// Remove ValDef for right-associative by-value operator desugaring which has been inlined into expr1
24882488
val statsTyped2 = statsTyped match {
2489-
case (vd: ValDef) :: Nil if inlinedRightAssocValDefs contains vd.symbol => Nil
2489+
case (vd: ValDef) :: Nil if inlinedRightAssocValDefs remove vd.symbol => Nil
24902490
case _ => statsTyped
24912491
}
24922492

@@ -3611,7 +3611,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
36113611
val args2 = (args1, mt.params) match {
36123612
case ((ident: Ident) :: Nil, param :: Nil) if param.isByNameParam && rightAssocValDefs.contains(ident.symbol) =>
36133613
inlinedRightAssocValDefs += ident.symbol
3614-
val rhs = rightAssocValDefs(ident.symbol)
3614+
val rhs = rightAssocValDefs.remove(ident.symbol).get
36153615
rhs.changeOwner(ident.symbol -> context.owner) :: Nil
36163616
case _ => args1
36173617
}

test/files/run/t1980.check

+6
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,9 @@ hi
2121
1
2222
1
2323
1
24+
5. defining
25+
Int 1
26+
Int 3
27+
5. forcing
28+
String 4
29+
String 2

test/files/run/t1980.scala

+17
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ object Test extends App {
4343
println(x1())
4444
}
4545

46+
// Ensure the owner chain is changed correctly when inlining
4647
{
4748
println("4. defining")
4849
class C { def f_:(x: => Int): () => Int = (() => x) }
@@ -55,4 +56,20 @@ object Test extends App {
5556
println(x2())
5657
println(x3())
5758
}
59+
60+
// Overloaded operator with by-name and by-value variants
61+
{
62+
println("5. defining")
63+
class C {
64+
val saved = new collection.mutable.ArrayBuffer[() => String]
65+
def force: Unit = saved.foreach(_.apply())
66+
def :: (x: Int): C = this
67+
def :: (x: => String): C = { saved += (() => x); this }
68+
}
69+
def genI(i: Int): Int = { println("Int "+i); i }
70+
def genS(s: String): String = { println("String "+s); s }
71+
val c = genI(1) :: genS("2") :: genI(3) :: genS("4") :: (new C)
72+
println("5. forcing")
73+
c.force
74+
}
5875
}

0 commit comments

Comments
 (0)