diff options
author | Adriaan Moors <adriaan@lightbend.com> | 2016-09-28 11:40:39 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-28 11:40:39 -0700 |
commit | 3b5d4e25e9409eca87c03b0374cd8e6946554546 (patch) | |
tree | a758048046d268e331fc776ae48a01ea7c44e3ef | |
parent | 50fca2d66388f43e4a6b4ae7cd70b5a21eb57aa3 (diff) | |
parent | e3e1e30c08d8bb532ac1d36d191fc8d4dbab0eb9 (diff) | |
download | scala-3b5d4e25e9409eca87c03b0374cd8e6946554546.tar.gz scala-3b5d4e25e9409eca87c03b0374cd8e6946554546.tar.bz2 scala-3b5d4e25e9409eca87c03b0374cd8e6946554546.zip |
Merge pull request #5397 from retronym/ticket/9920
SI-9920 Avoid linkage errors with captured local objects + self types
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala | 2 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/LambdaLift.scala | 9 | ||||
-rw-r--r-- | test/files/pos/t9920.scala | 6 | ||||
-rw-r--r-- | test/files/run/t9920.scala | 17 | ||||
-rw-r--r-- | test/files/run/t9920b.scala | 17 | ||||
-rw-r--r-- | test/files/run/t9920c.scala | 21 | ||||
-rw-r--r-- | test/files/run/t9920d.scala | 14 |
7 files changed, 84 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala index f3d5ceb0f0..7d50c12852 100644 --- a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala +++ b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala @@ -8,7 +8,7 @@ package tools.nsc package transform import symtab._ -import Flags.{ CASE => _, _ } +import Flags.{CASE => _, _} import scala.collection.mutable.ListBuffer /** This class ... diff --git a/src/compiler/scala/tools/nsc/transform/LambdaLift.scala b/src/compiler/scala/tools/nsc/transform/LambdaLift.scala index 74e6c58388..10d9c5627b 100644 --- a/src/compiler/scala/tools/nsc/transform/LambdaLift.scala +++ b/src/compiler/scala/tools/nsc/transform/LambdaLift.scala @@ -319,7 +319,14 @@ abstract class LambdaLift extends InfoTransform { else if (clazz.isStaticOwner) gen.mkAttributedQualifier(clazz.thisType) else outerValue match { case EmptyTree => prematureSelfReference() - case o => outerPath(o, currentClass.outerClass, clazz) + case o => + val path = outerPath(o, currentClass.outerClass, clazz) + if (path.tpe <:< clazz.tpeHK) path + else { + // SI-9920 The outer accessor might have an erased type of the self type of a trait, + // rather than the trait itself. Add a cast if necessary. + gen.mkAttributedCast(path, clazz.tpeHK) + } } } diff --git a/test/files/pos/t9920.scala b/test/files/pos/t9920.scala new file mode 100644 index 0000000000..8612618cc4 --- /dev/null +++ b/test/files/pos/t9920.scala @@ -0,0 +1,6 @@ +object Test { + def o = { + def i: Int = { i; 0 } + i + } +} diff --git a/test/files/run/t9920.scala b/test/files/run/t9920.scala new file mode 100644 index 0000000000..5dc32e99b7 --- /dev/null +++ b/test/files/run/t9920.scala @@ -0,0 +1,17 @@ +class C0 +trait T { self: C0 => + def test = { + object Local + + class C1 { + Local + } + new C1() + } +} + +object Test extends C0 with T { + def main(args: Array[String]): Unit = { + test + } +} diff --git a/test/files/run/t9920b.scala b/test/files/run/t9920b.scala new file mode 100644 index 0000000000..fab196b669 --- /dev/null +++ b/test/files/run/t9920b.scala @@ -0,0 +1,17 @@ +class C0 +trait T { + def test = { + object Local + + class C1 { + Local + } + new C1() + } +} + +object Test extends C0 with T { + def main(args: Array[String]): Unit = { + test + } +} diff --git a/test/files/run/t9920c.scala b/test/files/run/t9920c.scala new file mode 100644 index 0000000000..9541dc650a --- /dev/null +++ b/test/files/run/t9920c.scala @@ -0,0 +1,21 @@ +class C0 +trait T { self: C0 => + def test = { + object Local + + class C2 { + class C1 { + Local + } + T.this.toString + new C1 + } + new C2() + } +} + +object Test extends C0 with T { + def main(args: Array[String]): Unit = { + test + } +} diff --git a/test/files/run/t9920d.scala b/test/files/run/t9920d.scala new file mode 100644 index 0000000000..debc99e199 --- /dev/null +++ b/test/files/run/t9920d.scala @@ -0,0 +1,14 @@ +class C { object O } +trait T { _: C => + def foo { + class D { O } + new D + } +} + + +object Test extends C with T { + def main(args: Array[String]): Unit = { + foo + } +} |