diff options
-rw-r--r-- | compiler/src/dotty/tools/dotc/core/Contexts.scala | 3 | ||||
-rw-r--r-- | compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala | 3 | ||||
-rw-r--r-- | tests/repl/innerClasses.check | 5 |
3 files changed, 10 insertions, 1 deletions
diff --git a/compiler/src/dotty/tools/dotc/core/Contexts.scala b/compiler/src/dotty/tools/dotc/core/Contexts.scala index a1b99d16d..29629e505 100644 --- a/compiler/src/dotty/tools/dotc/core/Contexts.scala +++ b/compiler/src/dotty/tools/dotc/core/Contexts.scala @@ -262,6 +262,9 @@ object Contexts { final def withPhaseNoLater(phase: Phase) = if (phase.exists && ctx.phase.id > phase.id) withPhase(phase) else ctx + final def withPhaseNoEarlier(phase: Phase) = + if (phase.exists && ctx.phase.id < phase.id) withPhase(phase) else ctx + /** If -Ydebug is on, the top of the stack trace where this context * was created, otherwise `null`. */ diff --git a/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala b/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala index a32e1c921..4c5186712 100644 --- a/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala +++ b/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala @@ -147,7 +147,8 @@ object ExplicitOuter { private def newOuterSym(owner: ClassSymbol, cls: ClassSymbol, name: TermName, flags: FlagSet)(implicit ctx: Context) = { val target = cls.owner.enclosingClass.typeRef val info = if (flags.is(Method)) ExprType(target) else target - ctx.newSymbol(owner, name, Synthetic | flags, info, coord = cls.coord) + ctx.withPhaseNoEarlier(ctx.explicitOuterPhase.next) // outer accessors are entered at explicitOuter + 1, should not be defined before. + .newSymbol(owner, name, Synthetic | flags, info, coord = cls.coord) } /** A new param accessor for the outer field in class `cls` */ diff --git a/tests/repl/innerClasses.check b/tests/repl/innerClasses.check new file mode 100644 index 000000000..72dc6ae45 --- /dev/null +++ b/tests/repl/innerClasses.check @@ -0,0 +1,5 @@ +scala> class A { class Inner } +defined class A +scala> class B extends A { class Inner2 extends super.Inner } +defined class B +scala> :quit |