@@ -150,32 +150,34 @@ class Constructors extends MiniPhase with IdentityDenotTransformer { thisPhase =
150
150
// drop the () when replacing by the parameter.
151
151
object intoConstr extends TreeMap {
152
152
private var inSuperCall = false
153
- override def transform (tree : Tree )(using Context ): Tree = tree match {
154
- case Ident (_) | Select (This (_), _) =>
155
- var sym = tree.symbol
156
- def isOverridableSelect = tree.isInstanceOf [Select ] && ! sym.isEffectivelyFinal
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.
160
- // Variables need to go through the getter since they might have been updated.
161
- // References via this need to use the getter as well as long as that getter
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
170
- sym = sym.subst(accessors, paramSyms)
171
- if sym.maybeOwner.isConstructor then ref(sym).withSpan(tree.span) else tree
172
- case Apply (fn, Nil ) =>
173
- val fn1 = transform(fn)
174
- if ((fn1 ne fn) && fn1.symbol.is(Param ) && fn1.symbol.owner.isPrimaryConstructor)
175
- fn1 // in this case, fn1.symbol was an alias for a parameter in a superclass
176
- else cpy.Apply (tree)(fn1, Nil )
177
- case _ =>
178
- if (noDirectRefsFrom(tree)) tree else super .transform(tree)
153
+ override def transform (tree : Tree )(using Context ): Tree = inContext(transformCtx(tree)) {
154
+ tree match {
155
+ case Ident (_) | Select (This (_), _) =>
156
+ var sym = tree.symbol
157
+ def isOverridableSelect = tree.isInstanceOf [Select ] && ! sym.isEffectivelyFinal
158
+ def switchOutsideSupercall = ! sym.is(Mutable ) && ! isOverridableSelect
159
+ // If true, switch to constructor parameters also in the constructor body
160
+ // that follows the super call.
161
+ // Variables need to go through the getter since they might have been updated.
162
+ // References via this need to use the getter as well as long as that getter
163
+ // can be overridden. This is needed to handle overrides correctly. See run/i15723.scala.
164
+ // Note that in a supercall we need to switch to parameters in any case since then
165
+ // calling the virtual getter call would be illegal.
166
+ //
167
+ // Note: We intentionally treat references via this and identifiers differently
168
+ // here. Identifiers in a constructor always bind to the parameter. This is
169
+ // done for backwards compatbility.
170
+ if sym.is(ParamAccessor ) && (switchOutsideSupercall || inSuperCall) then
171
+ sym = sym.subst(accessors, paramSyms)
172
+ if sym.maybeOwner.isConstructor then ref(sym).withSpan(tree.span) else tree
173
+ case Apply (fn, Nil ) =>
174
+ val fn1 = transform(fn)
175
+ if ((fn1 ne fn) && fn1.symbol.is(Param ) && fn1.symbol.owner.isPrimaryConstructor)
176
+ fn1 // in this case, fn1.symbol was an alias for a parameter in a superclass
177
+ else cpy.Apply (tree)(fn1, Nil )
178
+ case _ =>
179
+ if (noDirectRefsFrom(tree)) tree else super .transform(tree)
180
+ }
179
181
}
180
182
181
183
def apply (tree : Tree , prevOwner : Symbol )(using Context ): Tree =
0 commit comments