Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 3310670

Browse files
liamappelbecommit-bot@chromium.org
authored andcommitted
[vm] Fix late field store bug
Late field stores were being incorrectly marked as initializations, causing them to be incorrectly optimised out in some cases. Change-Id: I7487d24238af3b3922e76a9ca6ae6df4bf5ab849 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138566 Reviewed-by: Alexander Markov <[email protected]> Reviewed-by: Liam Appelbe <[email protected]> Commit-Queue: Liam Appelbe <[email protected]>
1 parent 9d76737 commit 3310670

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

runtime/vm/compiler/frontend/kernel_to_il.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,8 +566,7 @@ Fragment FlowGraphBuilder::StoreLateField(const Field& field,
566566
if (is_static) {
567567
instructions += StoreStaticField(position, field);
568568
} else {
569-
instructions += StoreInstanceFieldGuarded(
570-
field, StoreInstanceFieldInstr::Kind::kInitializing);
569+
instructions += StoreInstanceFieldGuarded(field);
571570
}
572571

573572
return instructions;

tests/language/nnbd/syntax/late_modifier_non_final_field_test.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class A {
1717
late int fieldWithTrivialInit = 123;
1818
late int? fieldWithNullInit = null;
1919
late int fieldWithNoInit;
20+
late int? nullableFieldWithNoInit;
2021
}
2122

2223
main() {
@@ -29,22 +30,28 @@ main() {
2930
Expect.equals(null, a.fieldWithNullInit);
3031
Expect.throws(
3132
() => a.fieldWithNoInit, (error) => error is LateInitializationError);
33+
Expect.throws(() => a.nullableFieldWithNoInit,
34+
(error) => error is LateInitializationError);
3235
Expect.equals(1, initCalls);
3336
Expect.equals(123, a.fieldWithInit);
3437
Expect.equals(123, a.fieldWithTrivialInit);
3538
Expect.equals(null, a.fieldWithNullInit);
3639
Expect.throws(
3740
() => a.fieldWithNoInit, (error) => error is LateInitializationError);
41+
Expect.throws(() => a.nullableFieldWithNoInit,
42+
(error) => error is LateInitializationError);
3843
Expect.equals(1, initCalls);
3944
a.fieldWithInit = 456;
4045
a.fieldWithTrivialInit = 456;
4146
a.fieldWithNullInit = 456;
4247
a.fieldWithNoInit = 456;
48+
a.nullableFieldWithNoInit = null;
4349
Expect.equals(1, initCalls);
4450
Expect.equals(456, a.fieldWithInit);
4551
Expect.equals(456, a.fieldWithTrivialInit);
4652
Expect.equals(456, a.fieldWithNullInit);
4753
Expect.equals(456, a.fieldWithNoInit);
54+
Expect.equals(null, a.nullableFieldWithNoInit);
4855
Expect.equals(1, initCalls);
4956
initCalls = 0;
5057

0 commit comments

Comments
 (0)