Skip to content

fix #2163: don't narrow liftedOwner if symbol is InSuperCall #2216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 11, 2017
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
12 changes: 8 additions & 4 deletions compiler/src/dotty/tools/dotc/transform/LambdaLift.scala
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,17 @@ class LambdaLift extends MiniPhase with IdentityDenotTransformer { thisTransform
/** Set `liftedOwner(sym)` to `owner` if `owner` is more deeply nested
* than the previous value of `liftedowner(sym)`.
*/
def narrowLiftedOwner(sym: Symbol, owner: Symbol)(implicit ctx: Context) =
def narrowLiftedOwner(sym: Symbol, owner: Symbol)(implicit ctx: Context): Unit =
if (sym.maybeOwner.isTerm &&
owner.isProperlyContainedIn(liftedOwner(sym)) &&
owner != sym) {
ctx.log(i"narrow lifted $sym to $owner")
changedLiftedOwner = true
liftedOwner(sym) = owner
if (sym.is(InSuperCall) && owner.isProperlyContainedIn(sym.enclosingClass))
narrowLiftedOwner(sym, sym.enclosingClass)
else {
ctx.log(i"narrow lifted $sym to $owner")
changedLiftedOwner = true
liftedOwner(sym) = owner
}
}

/** Mark symbol `sym` as being free in `enclosure`, unless `sym` is defined
Expand Down
21 changes: 21 additions & 0 deletions tests/run/i2163.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Base(f: Int => Int) {
def result = f(3)
}

class Child(x: Int) extends Base(y => x + y)

class Outer(z: Int) {
class Base(f: Int => Int) {
def result = f(3)
}

class Child(x: Int) extends Base(y => x + y + z)
}

object Test {
def main(args: Array[String]): Unit = {
assert(new Child(4).result == 7)
val o = new Outer(2)
assert(new o.Child(2).result == 7)
}
}