Skip to content

Commit 50bcb1a

Browse files
authored
Merge pull request #1813 from dotty-staging/fix-#1806
Fix #1806: Define outer accessors at the right phase
2 parents 8643876 + e4fd920 commit 50bcb1a

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

compiler/src/dotty/tools/dotc/core/Contexts.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ object Contexts {
262262
final def withPhaseNoLater(phase: Phase) =
263263
if (phase.exists && ctx.phase.id > phase.id) withPhase(phase) else ctx
264264

265+
final def withPhaseNoEarlier(phase: Phase) =
266+
if (phase.exists && ctx.phase.id < phase.id) withPhase(phase) else ctx
267+
265268
/** If -Ydebug is on, the top of the stack trace where this context
266269
* was created, otherwise `null`.
267270
*/

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ object ExplicitOuter {
147147
private def newOuterSym(owner: ClassSymbol, cls: ClassSymbol, name: TermName, flags: FlagSet)(implicit ctx: Context) = {
148148
val target = cls.owner.enclosingClass.typeRef
149149
val info = if (flags.is(Method)) ExprType(target) else target
150-
ctx.newSymbol(owner, name, Synthetic | flags, info, coord = cls.coord)
150+
ctx.withPhaseNoEarlier(ctx.explicitOuterPhase.next) // outer accessors are entered at explicitOuter + 1, should not be defined before.
151+
.newSymbol(owner, name, Synthetic | flags, info, coord = cls.coord)
151152
}
152153

153154
/** A new param accessor for the outer field in class `cls` */

tests/neg/i1806.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
trait A {
2+
class Inner
3+
}
4+
trait B extends A {
5+
class Inner extends super.Inner // error
6+
}
7+

tests/repl/innerClasses.check

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
scala> class A { class Inner }
2+
defined class A
3+
scala> class B extends A { class Inner2 extends super.Inner }
4+
defined class B
5+
scala> :quit

0 commit comments

Comments
 (0)