diff options
author | liu fengyun <liu@fengy.me> | 2016-12-18 00:56:18 +0100 |
---|---|---|
committer | liu fengyun <liu@fengy.me> | 2016-12-18 00:57:02 +0100 |
commit | 152e4690edd3e5ad484519baccdf679cfa0919ed (patch) | |
tree | 33f71b3956d1a49da586915b63b64acf31d5d0d1 | |
parent | 5df985cc599a0c69029773e3416bbb5fc883476a (diff) | |
download | dotty-152e4690edd3e5ad484519baccdf679cfa0919ed.tar.gz dotty-152e4690edd3e5ad484519baccdf679cfa0919ed.tar.bz2 dotty-152e4690edd3e5ad484519baccdf679cfa0919ed.zip |
fix #1820: make sure outer of traits implemented
-rw-r--r-- | compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala | 19 | ||||
-rw-r--r-- | tests/run/i1820.check | 1 | ||||
-rw-r--r-- | tests/run/i1820.scala | 17 |
3 files changed, 30 insertions, 7 deletions
diff --git a/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala b/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala index 5463d5080..e792518ce 100644 --- a/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala +++ b/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala @@ -81,14 +81,19 @@ class ExplicitOuter extends MiniPhaseTransform with InfoTransformer { thisTransf !needsOuterAlways(cls) && impl.existsSubTree(referencesOuter(cls, _))) ensureOuterAccessors(cls) - if (hasOuter(cls)) { + + val hasOuterFlag = hasOuter(cls) + if (hasOuterFlag || cls.mixins.exists(needsOuterIfReferenced)) { val newDefs = new mutable.ListBuffer[Tree] - if (isTrait) - newDefs += DefDef(outerAccessor(cls).asTerm, EmptyTree) - else { - val outerParamAcc = outerParamAccessor(cls) - newDefs += ValDef(outerParamAcc, EmptyTree) - newDefs += DefDef(outerAccessor(cls).asTerm, ref(outerParamAcc)) + + if (hasOuterFlag) { + if (isTrait) + newDefs += DefDef(outerAccessor(cls).asTerm, EmptyTree) + else { + val outerParamAcc = outerParamAccessor(cls) + newDefs += ValDef(outerParamAcc, EmptyTree) + newDefs += DefDef(outerAccessor(cls).asTerm, ref(outerParamAcc)) + } } for (parentTrait <- cls.mixins) { diff --git a/tests/run/i1820.check b/tests/run/i1820.check new file mode 100644 index 000000000..789819226 --- /dev/null +++ b/tests/run/i1820.check @@ -0,0 +1 @@ +a diff --git a/tests/run/i1820.scala b/tests/run/i1820.scala new file mode 100644 index 000000000..bc4f63d9b --- /dev/null +++ b/tests/run/i1820.scala @@ -0,0 +1,17 @@ +class A { + val a = "a" + trait Inner { + def f = println(a) + def h = 3 + } +} + +class Inner extends O.a.Inner + +object O { + val a = new A + + def main(args: Array[String]): Unit = { + (new Inner).f + } +} |