Skip to content

Commit

Permalink
Avoid too eager transform of for lhs & accessor rhs
Browse files Browse the repository at this point in the history
  • Loading branch information
szymon-rd committed Nov 16, 2023
1 parent 18ada51 commit a8057d4
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/Constructors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Symbols.*
import Decorators.*
import DenotTransformers.*
import collection.mutable
import Types.*

object Constructors {
val name: String = "constructors"
Expand Down Expand Up @@ -193,10 +194,14 @@ class Constructors extends MiniPhase with IdentityDenotTransformer { thisPhase =
override def transform(tree: Tree)(using Context) = tree match {
case Apply(fn, Nil)
if (fn.symbol.is(OuterAccessor)
|| fn.symbol.isGetter && fn.symbol.name == nme.OUTER
) &&
fn.symbol.info.resultType.classSymbol == outerParam.info.classSymbol =>
|| fn.symbol.isGetter && fn.symbol.name == nme.OUTER
) &&
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 _ =>
Expand Down

0 comments on commit a8057d4

Please # to comment.