Skip to content

Commit 72bbc30

Browse files
committed
Fix #1820: condition of whether generates outer
Previously, we don't generate `outer` for the annoymous class `Inner3`, because it doesn't reference the symbol `B`. This is incorrect, as `Inner3` extends `A`, 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 class Inner3 extends Inner2 }
1 parent 152e469 commit 72bbc30

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ class ExplicitOuter extends MiniPhaseTransform with InfoTransformer { thisTransf
7979
val isTrait = cls.is(Trait)
8080
if (needsOuterIfReferenced(cls) &&
8181
!needsOuterAlways(cls) &&
82-
impl.existsSubTree(referencesOuter(cls, _)))
82+
(cls.mixins.exists(needsOuterIfReferenced) ||
83+
impl.existsSubTree(referencesOuter(cls, _))))
8384
ensureOuterAccessors(cls)
8485

8586
val hasOuterFlag = hasOuter(cls)

tests/run/i1820b.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a

tests/run/i1820b.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
trait A {
2+
val a = "a"
3+
trait Inner {
4+
def f = println(a)
5+
def h = 3
6+
}
7+
}
8+
9+
trait B extends A {
10+
trait Inner2 extends Inner
11+
def g = new Inner2 {}
12+
}
13+
14+
object O {
15+
def main(args: Array[String]): Unit = {
16+
val b = new B {}
17+
b.g.f
18+
}
19+
}

0 commit comments

Comments
 (0)