Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions compiler/src/dotty/tools/dotc/transform/LambdaLift.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dotty.tools.dotc
package transform

import MegaPhase._
import core.Denotations.NonSymSingleDenotation
import core.DenotTransformers._
import core.Symbols._
import core.Contexts._
Expand Down Expand Up @@ -549,6 +550,16 @@ class LambdaLift extends MiniPhase with IdentityDenotTransformer { thisPhase =>
}
}

override def transformSelect(tree: Select)(using Context): Tree =
val denot = tree.denot
val sym = tree.symbol
// The Lifter updates the type of symbols using `installAfter` to give them a
// new `SymDenotation`, but that doesn't affect non-sym denotations, so we
// reload them manually here.
if denot.isInstanceOf[NonSymSingleDenotation] && lifter.free.contains(sym) then
tree.qualifier.select(sym).withSpan(tree.span)
else tree

override def transformApply(tree: Apply)(using Context): Apply =
cpy.Apply(tree)(tree.fun, lifter.addFreeArgs(tree.symbol, tree.args)).withSpan(tree.span)

Expand Down
9 changes: 9 additions & 0 deletions tests/pos/t6231c.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
object Bug {
def bar(ev: Any) = {
trait X(val x: Int) {
def qux: () => x.type = { () => println(ev); x }
}
(new X(1) {}).qux()
}
}