From ff782651ee5e5a3aa9a3d1b72b2b1fdaa26eafca Mon Sep 17 00:00:00 2001 From: liu fengyun Date: Mon, 10 Apr 2017 17:28:57 +0200 Subject: fix #2163: don't narrow liftedOwner if symbol is InSuperCall --- compiler/src/dotty/tools/dotc/transform/LambdaLift.scala | 1 + tests/run/i2163.check | 1 + tests/run/i2163.scala | 9 +++++++++ 3 files changed, 11 insertions(+) create mode 100644 tests/run/i2163.check create mode 100644 tests/run/i2163.scala diff --git a/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala b/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala index 7578b57f1..3880b6efb 100644 --- a/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala +++ b/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala @@ -146,6 +146,7 @@ class LambdaLift extends MiniPhase with IdentityDenotTransformer { thisTransform def narrowLiftedOwner(sym: Symbol, owner: Symbol)(implicit ctx: Context) = if (sym.maybeOwner.isTerm && owner.isProperlyContainedIn(liftedOwner(sym)) && + !sym.is(InSuperCall) && owner != sym) { ctx.log(i"narrow lifted $sym to $owner") changedLiftedOwner = true diff --git a/tests/run/i2163.check b/tests/run/i2163.check new file mode 100644 index 000000000..7f8f011eb --- /dev/null +++ b/tests/run/i2163.check @@ -0,0 +1 @@ +7 diff --git a/tests/run/i2163.scala b/tests/run/i2163.scala new file mode 100644 index 000000000..67c4adb31 --- /dev/null +++ b/tests/run/i2163.scala @@ -0,0 +1,9 @@ +class Base(f: Int => Int) { + f(3) +} + +class Child(x: Int) extends Base(y => x + y) + +object Test { + def main(args: Array[String]): Unit = new Child(4) +} -- cgit v1.2.3 From e4a6d72a52b4b9c3ce5530197352ca11e11fc9aa Mon Sep 17 00:00:00 2001 From: liu fengyun Date: Mon, 10 Apr 2017 18:24:38 +0200 Subject: add missing print --- tests/run/i2163.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/run/i2163.scala b/tests/run/i2163.scala index 67c4adb31..a187cd4c8 100644 --- a/tests/run/i2163.scala +++ b/tests/run/i2163.scala @@ -1,5 +1,5 @@ class Base(f: Int => Int) { - f(3) + println(f(3)) } class Child(x: Int) extends Base(y => x + y) -- cgit v1.2.3 From 0eb06db64b66a63d722ba580d5e94506febd9dc8 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 11 Apr 2017 09:22:56 +0200 Subject: Handle supercalls in inner classes correctly The previous fix was too coarse. We need to move an anonymous function in a supercall towards the call, we just have to make sure it's not in the directly enclosing class. --- compiler/src/dotty/tools/dotc/transform/LambdaLift.scala | 13 ++++++++----- tests/run/i2163.scala | 16 ++++++++++++++-- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala b/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala index 3880b6efb..a729368d4 100644 --- a/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala +++ b/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala @@ -143,14 +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)) && - !sym.is(InSuperCall) && 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 diff --git a/tests/run/i2163.scala b/tests/run/i2163.scala index a187cd4c8..952f651e3 100644 --- a/tests/run/i2163.scala +++ b/tests/run/i2163.scala @@ -1,9 +1,21 @@ class Base(f: Int => Int) { - println(f(3)) + 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 = new Child(4) + def main(args: Array[String]): Unit = { + assert(new Child(4).result == 7) + val o = new Outer(2) + assert(new o.Child(2).result == 7) + } } -- cgit v1.2.3 From 48c37927bd95f5e6bb9f71d02def7e2fef125202 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 11 Apr 2017 09:29:42 +0200 Subject: Remove check file --- tests/run/i2163.check | 1 - 1 file changed, 1 deletion(-) delete mode 100644 tests/run/i2163.check diff --git a/tests/run/i2163.check b/tests/run/i2163.check deleted file mode 100644 index 7f8f011eb..000000000 --- a/tests/run/i2163.check +++ /dev/null @@ -1 +0,0 @@ -7 -- cgit v1.2.3