aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorliu fengyun <liu@fengy.me>2016-12-19 14:08:36 +0100
committerliu fengyun <liu@fengy.me>2016-12-19 15:08:59 +0100
commitbfabceeb1d19848e86f69019a4614c3653420ccc (patch)
tree24765b7cc31ad1763ee05875190bf008a9192a28
parent152e4690edd3e5ad484519baccdf679cfa0919ed (diff)
downloaddotty-bfabceeb1d19848e86f69019a4614c3653420ccc.tar.gz
dotty-bfabceeb1d19848e86f69019a4614c3653420ccc.tar.bz2
dotty-bfabceeb1d19848e86f69019a4614c3653420ccc.zip
Fix #1820: condition of whether generates outer
Previously, we don't generate `outer` for the anonymous class `new Inner2 {}`. This is incorrect, as `Inner2 {}` extends `A.Inner`, which requires an outer. trait A { val a = "a" trait Inner { def f = println(a) def h = 3 } } trait B extends A { trait Inner2 extends Inner new Inner2 {} }
-rw-r--r--compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala3
-rw-r--r--tests/run/i1820.scala4
-rw-r--r--tests/run/i1820b.check1
-rw-r--r--tests/run/i1820b.scala19
4 files changed, 24 insertions, 3 deletions
diff --git a/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala b/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala
index e792518ce..007210926 100644
--- a/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala
+++ b/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala
@@ -79,7 +79,8 @@ class ExplicitOuter extends MiniPhaseTransform with InfoTransformer { thisTransf
val isTrait = cls.is(Trait)
if (needsOuterIfReferenced(cls) &&
!needsOuterAlways(cls) &&
- impl.existsSubTree(referencesOuter(cls, _)))
+ (cls.mixins.exists(needsOuterIfReferenced) ||
+ impl.existsSubTree(referencesOuter(cls, _))))
ensureOuterAccessors(cls)
val hasOuterFlag = hasOuter(cls)
diff --git a/tests/run/i1820.scala b/tests/run/i1820.scala
index bc4f63d9b..b39e6d108 100644
--- a/tests/run/i1820.scala
+++ b/tests/run/i1820.scala
@@ -6,9 +6,9 @@ class A {
}
}
-class Inner extends O.a.Inner
+class Inner extends Test.a.Inner
-object O {
+object Test {
val a = new A
def main(args: Array[String]): Unit = {
diff --git a/tests/run/i1820b.check b/tests/run/i1820b.check
new file mode 100644
index 000000000..789819226
--- /dev/null
+++ b/tests/run/i1820b.check
@@ -0,0 +1 @@
+a
diff --git a/tests/run/i1820b.scala b/tests/run/i1820b.scala
new file mode 100644
index 000000000..3452b6158
--- /dev/null
+++ b/tests/run/i1820b.scala
@@ -0,0 +1,19 @@
+trait A {
+ val a = "a"
+ trait Inner {
+ def f = println(a)
+ def h = 3
+ }
+}
+
+trait B extends A {
+ trait Inner2 extends Inner
+ def g = new Inner2 {}
+}
+
+object Test {
+ def main(args: Array[String]): Unit = {
+ val b = new B {}
+ b.g.f
+ }
+}