File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed
compiler/src/dotty/tools/dotc/transform/init Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -753,6 +753,7 @@ object Objects:
753
753
assert(sym.is(Flags .Mutable ), " Writing to immutable variable " + sym.show)
754
754
Env .resolveEnv(sym.enclosingMethod, thisV, summon[Env .Data ]) match
755
755
case Some (thisV -> env) =>
756
+ given Env .Data = env
756
757
val addr = Env .varAddr(sym)
757
758
if addr.owner != State .currentObject then
758
759
errorMutateOtherStaticObject(State .currentObject, addr.owner)
@@ -1092,7 +1093,12 @@ object Objects:
1092
1093
// init param fields
1093
1094
klass.paramGetters.foreach { acc =>
1094
1095
val value = paramsMap(acc.name.toTermName)
1095
- thisV.initVal(acc, value)
1096
+ if acc.is(Flags .Mutable ) then
1097
+ val addr = Heap .fieldVarAddr(thisV, acc, State .currentObject)
1098
+ thisV.initVar(acc, addr)
1099
+ Heap .write(addr, value)
1100
+ else
1101
+ thisV.initVal(acc, value)
1096
1102
printer.println(acc.show + " initialized with " + value)
1097
1103
}
1098
1104
Original file line number Diff line number Diff line change
1
+ import scala .annotation .init
2
+
1
3
object A :
2
4
class Pair (val f : Int => Unit , val g : () => Int )
3
5
val p : Pair = foo()
4
6
5
7
def foo (): Pair =
6
8
var x = 6
7
- new Pair (y => x = y, () => x)
8
-
9
+ new Pair (
10
+ (y => x = y): @ init.expose, // error
11
+ () => x
12
+ )
9
13
10
14
object B :
11
- A .p.f(10 ) // error
15
+ A .p.f(10 )
You can’t perform that action at this time.
0 commit comments