aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorodersky <odersky@gmail.com>2017-04-11 17:32:27 +0200
committerGitHub <noreply@github.com>2017-04-11 17:32:27 +0200
commitf13e3a43d227933ce644f2503f658ea436ea11b4 (patch)
treecfbb32705c038aab021d5f95267135a8a031490f
parent9917029becab32d56e786ac9309ee195737f6da0 (diff)
parent48c37927bd95f5e6bb9f71d02def7e2fef125202 (diff)
downloaddotty-f13e3a43d227933ce644f2503f658ea436ea11b4.tar.gz
dotty-f13e3a43d227933ce644f2503f658ea436ea11b4.tar.bz2
dotty-f13e3a43d227933ce644f2503f658ea436ea11b4.zip
Merge pull request #2216 from dotty-staging/fix-2163
fix #2163: don't narrow liftedOwner if symbol is InSuperCall
-rw-r--r--compiler/src/dotty/tools/dotc/transform/LambdaLift.scala12
-rw-r--r--tests/run/i2163.scala21
2 files changed, 29 insertions, 4 deletions
diff --git a/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala b/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala
index 7578b57f1..a729368d4 100644
--- a/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala
+++ b/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala
@@ -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
diff --git a/tests/run/i2163.scala b/tests/run/i2163.scala
new file mode 100644
index 000000000..952f651e3
--- /dev/null
+++ b/tests/run/i2163.scala
@@ -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)
+ }
+}