Skip to content

Commit a8057d4

Browse files
committed
Avoid too eager transform of for lhs & accessor rhs
1 parent 18ada51 commit a8057d4

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import Symbols.*
1515
import Decorators.*
1616
import DenotTransformers.*
1717
import collection.mutable
18+
import Types.*
1819

1920
object Constructors {
2021
val name: String = "constructors"
@@ -193,10 +194,14 @@ class Constructors extends MiniPhase with IdentityDenotTransformer { thisPhase =
193194
override def transform(tree: Tree)(using Context) = tree match {
194195
case Apply(fn, Nil)
195196
if (fn.symbol.is(OuterAccessor)
196-
|| fn.symbol.isGetter && fn.symbol.name == nme.OUTER
197-
) &&
198-
fn.symbol.info.resultType.classSymbol == outerParam.info.classSymbol =>
197+
|| fn.symbol.isGetter && fn.symbol.name == nme.OUTER
198+
) &&
199+
fn.symbol.info.resultType.classSymbol == outerParam.info.classSymbol =>
199200
ref(outerParam)
201+
case Assign(lhs, rhs) if lhs.symbol.name == nme.OUTER => // not transform LHS of assignment to $outer field
202+
cpy.Assign(tree)(lhs, super.transform(rhs))
203+
case dd: DefDef if dd.name.endsWith(nme.OUTER.asSimpleName) => // not transform RHS of outer accessor
204+
dd
200205
case tree: RefTree if tree.symbol.is(ParamAccessor) && tree.symbol.name == nme.OUTER =>
201206
ref(outerParam)
202207
case _ =>

0 commit comments

Comments
 (0)