Skip to content

Commit f13e3a4

Browse files
authored
Merge pull request #2216 from dotty-staging/fix-2163
fix #2163: don't narrow liftedOwner if symbol is InSuperCall
2 parents 9917029 + 48c3792 commit f13e3a4

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,17 @@ class LambdaLift extends MiniPhase with IdentityDenotTransformer { thisTransform
143143
/** Set `liftedOwner(sym)` to `owner` if `owner` is more deeply nested
144144
* than the previous value of `liftedowner(sym)`.
145145
*/
146-
def narrowLiftedOwner(sym: Symbol, owner: Symbol)(implicit ctx: Context) =
146+
def narrowLiftedOwner(sym: Symbol, owner: Symbol)(implicit ctx: Context): Unit =
147147
if (sym.maybeOwner.isTerm &&
148148
owner.isProperlyContainedIn(liftedOwner(sym)) &&
149149
owner != sym) {
150-
ctx.log(i"narrow lifted $sym to $owner")
151-
changedLiftedOwner = true
152-
liftedOwner(sym) = owner
150+
if (sym.is(InSuperCall) && owner.isProperlyContainedIn(sym.enclosingClass))
151+
narrowLiftedOwner(sym, sym.enclosingClass)
152+
else {
153+
ctx.log(i"narrow lifted $sym to $owner")
154+
changedLiftedOwner = true
155+
liftedOwner(sym) = owner
156+
}
153157
}
154158

155159
/** Mark symbol `sym` as being free in `enclosure`, unless `sym` is defined

tests/run/i2163.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Base(f: Int => Int) {
2+
def result = f(3)
3+
}
4+
5+
class Child(x: Int) extends Base(y => x + y)
6+
7+
class Outer(z: Int) {
8+
class Base(f: Int => Int) {
9+
def result = f(3)
10+
}
11+
12+
class Child(x: Int) extends Base(y => x + y + z)
13+
}
14+
15+
object Test {
16+
def main(args: Array[String]): Unit = {
17+
assert(new Child(4).result == 7)
18+
val o = new Outer(2)
19+
assert(new o.Child(2).result == 7)
20+
}
21+
}

0 commit comments

Comments
 (0)