diff options
author | Dmitry Petrashko <dark@d-d.me> | 2016-12-16 10:53:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-16 10:53:26 +0100 |
commit | 50bcb1ac954436d011cf11a30ef0ee4a066c00d1 (patch) | |
tree | 97778694e7b61ae298ff2a79fa049a82f3786fef | |
parent | 8643876e31d6668555cf903c0a21ee49122f4f17 (diff) | |
parent | e4fd920fdc8e65738111837273a53548bcbb24b9 (diff) | |
download | dotty-50bcb1ac954436d011cf11a30ef0ee4a066c00d1.tar.gz dotty-50bcb1ac954436d011cf11a30ef0ee4a066c00d1.tar.bz2 dotty-50bcb1ac954436d011cf11a30ef0ee4a066c00d1.zip |
Merge pull request #1813 from dotty-staging/fix-#1806
Fix #1806: Define outer accessors at the right phase
-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/neg/i1806.scala | 7 | ||||
-rw-r--r-- | tests/repl/innerClasses.check | 5 |
4 files changed, 17 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/neg/i1806.scala b/tests/neg/i1806.scala new file mode 100644 index 000000000..7e5e132f2 --- /dev/null +++ b/tests/neg/i1806.scala @@ -0,0 +1,7 @@ +trait A { + class Inner + } +trait B extends A { + class Inner extends super.Inner // error +} + 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 |