File tree 3 files changed +18
-1
lines changed
compiler/src/dotty/tools/dotc/transform
3 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -146,10 +146,16 @@ class Constructors extends MiniPhase with IdentityDenotTransformer { thisPhase =
146
146
// (2) If the parameter accessor reference was to an alias getter,
147
147
// drop the () when replacing by the parameter.
148
148
object intoConstr extends TreeMap {
149
+ private var isSuperCall = false
149
150
override def transform (tree : Tree )(using Context ): Tree = tree match {
150
151
case Ident (_) | Select (This (_), _) =>
151
152
var sym = tree.symbol
152
- if (sym.is(ParamAccessor , butNot = Mutable )) sym = sym.subst(accessors, paramSyms)
153
+ if sym.is(ParamAccessor ) && (! sym.is(Mutable ) || isSuperCall)
154
+ // Variables need to go through the getter since they might have been updated,
155
+ // except if we are in a super call, since then the virtual getter call would
156
+ // be illegal.
157
+ then
158
+ sym = sym.subst(accessors, paramSyms)
153
159
if (sym.maybeOwner.isConstructor) ref(sym).withSpan(tree.span) else tree
154
160
case Apply (fn, Nil ) =>
155
161
val fn1 = transform(fn)
@@ -161,6 +167,7 @@ class Constructors extends MiniPhase with IdentityDenotTransformer { thisPhase =
161
167
}
162
168
163
169
def apply (tree : Tree , prevOwner : Symbol )(using Context ): Tree =
170
+ isSuperCall = isSuperConstrCall(tree)
164
171
transform(tree).changeOwnerAfter(prevOwner, constr.symbol, thisPhase)
165
172
}
166
173
Original file line number Diff line number Diff line change
1
+ it worked
Original file line number Diff line number Diff line change
1
+ class ClassWithLambda (sup : () => Long )
2
+ class ClassWithVar (var msg : String ) extends ClassWithLambda (() => 1 )
3
+
4
+ object Test :
5
+ val _ = new ClassWithVar (" foo" )
6
+
7
+ def main (args : Array [String ]): Unit = {
8
+ println(" it worked" )
9
+ }
You can’t perform that action at this time.
0 commit comments