@@ -154,14 +154,19 @@ class Constructors extends MiniPhase with IdentityDenotTransformer { thisPhase =
154154 case Ident (_) | Select (This (_), _) =>
155155 var sym = tree.symbol
156156 def isOverridableSelect = tree.isInstanceOf [Select ] && ! sym.isEffectivelyFinal
157- def keepUnlessInSuperCall = sym.is(Mutable ) || isOverridableSelect
158- // If true, switch to constructor parameters only in the super call.
157+ def switchOutsideSupercall = ! sym.is(Mutable ) && ! isOverridableSelect
158+ // If true, switch to constructor parameters also in the constructor body
159+ // that follows the super call.
159160 // Variables need to go through the getter since they might have been updated.
160161 // References via this need to use the getter as well as long as that getter
161- // can be overriddem. This is needed to handle overrides correctly. See run/i15723.scala.
162- // But in a supercall we need to switch to parameters in any case since then
163- // calling the virtual getter would be illegal.
164- if sym.is(ParamAccessor ) && (! keepUnlessInSuperCall || inSuperCall) then
162+ // can be overridden. This is needed to handle overrides correctly. See run/i15723.scala.
163+ // Note that in a supercall we need to switch to parameters in any case since then
164+ // calling the virtual getter call would be illegal.
165+ //
166+ // Note: We intentionally treat references via this and identifiers differently
167+ // here. Identifiers in a constructor always bind to the parameter. This is
168+ // done for backwards compatbility.
169+ if sym.is(ParamAccessor ) && (switchOutsideSupercall || inSuperCall) then
165170 sym = sym.subst(accessors, paramSyms)
166171 if sym.maybeOwner.isConstructor then ref(sym).withSpan(tree.span) else tree
167172 case Apply (fn, Nil ) =>
0 commit comments