Skip to content

Commit 33ece58

Browse files
authored
Merge pull request #11303 from dotty-staging/lambdalift-transformSelect
LambdaLift: reload non-sym denotations when needed
2 parents 65e8c40 + 694e713 commit 33ece58

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

compiler/src/dotty/tools/dotc/transform/LambdaLift.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package dotty.tools.dotc
22
package transform
33

44
import MegaPhase._
5+
import core.Denotations.NonSymSingleDenotation
56
import core.DenotTransformers._
67
import core.Symbols._
78
import core.Contexts._
@@ -549,6 +550,16 @@ class LambdaLift extends MiniPhase with IdentityDenotTransformer { thisPhase =>
549550
}
550551
}
551552

553+
override def transformSelect(tree: Select)(using Context): Tree =
554+
val denot = tree.denot
555+
val sym = tree.symbol
556+
// The Lifter updates the type of symbols using `installAfter` to give them a
557+
// new `SymDenotation`, but that doesn't affect non-sym denotations, so we
558+
// reload them manually here.
559+
if denot.isInstanceOf[NonSymSingleDenotation] && lifter.free.contains(sym) then
560+
tree.qualifier.select(sym).withSpan(tree.span)
561+
else tree
562+
552563
override def transformApply(tree: Apply)(using Context): Apply =
553564
cpy.Apply(tree)(tree.fun, lifter.addFreeArgs(tree.symbol, tree.args)).withSpan(tree.span)
554565

tests/pos/t6231c.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
object Bug {
2+
def bar(ev: Any) = {
3+
trait X(val x: Int) {
4+
def qux: () => x.type = { () => println(ev); x }
5+
}
6+
(new X(1) {}).qux()
7+
}
8+
}
9+

0 commit comments

Comments
 (0)