From 2ff4ba769e17e1eebd6419bfdbf9022129b5cd6a Mon Sep 17 00:00:00 2001 From: Szymon Rodziewicz Date: Thu, 16 Nov 2023 19:09:49 +0100 Subject: [PATCH] Avoid too eager transform of outer for lhs & accessor rhs --- .../dotty/tools/dotc/transform/Constructors.scala | 5 +++++ tests/pos/i18927.scala | 14 ++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 tests/pos/i18927.scala diff --git a/compiler/src/dotty/tools/dotc/transform/Constructors.scala b/compiler/src/dotty/tools/dotc/transform/Constructors.scala index 9df98292fe84..e465e42fe8d8 100644 --- a/compiler/src/dotty/tools/dotc/transform/Constructors.scala +++ b/compiler/src/dotty/tools/dotc/transform/Constructors.scala @@ -15,6 +15,7 @@ import Symbols.* import Decorators.* import DenotTransformers.* import collection.mutable +import Types.* object Constructors { val name: String = "constructors" @@ -197,6 +198,10 @@ class Constructors extends MiniPhase with IdentityDenotTransformer { thisPhase = ) && fn.symbol.info.resultType.classSymbol == outerParam.info.classSymbol => ref(outerParam) + case Assign(lhs, rhs) if lhs.symbol.name == nme.OUTER => // not transform LHS of assignment to $outer field + cpy.Assign(tree)(lhs, super.transform(rhs)) + case dd: DefDef if dd.name.endsWith(nme.OUTER.asSimpleName) => // not transform RHS of outer accessor + dd case tree: RefTree if tree.symbol.is(ParamAccessor) && tree.symbol.name == nme.OUTER => ref(outerParam) case _ => diff --git a/tests/pos/i18927.scala b/tests/pos/i18927.scala new file mode 100644 index 000000000000..1549335544c7 --- /dev/null +++ b/tests/pos/i18927.scala @@ -0,0 +1,14 @@ +class A + +class B { + val a = new A + + class C(i: Int) { + def this() = { + this(1) + class Inner() { + println(a) + } + } + } +} \ No newline at end of file