Skip to content

Commit 098d2f3

Browse files
derekxu16Commit Queue
authored andcommitted
[VM/Compiler] Mark instructions related to late initialization error checks as synthetic
TEST=pkg/vm_service/test/breakpoints_ignore_late_initialization_error_instructions_test.dart Fixes: #53376 Change-Id: Iab7d2489f29bfc4a586b9de6e3caa0a7c1a35454 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/355000 Reviewed-by: Ben Konyi <bkonyi@google.com> Commit-Queue: Derek Xu <derekx@google.com>
1 parent df72011 commit 098d2f3

File tree

2 files changed

+82
-2
lines changed

2 files changed

+82
-2
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// Regression test for https://dartbug.com/53376.
6+
7+
import 'common/service_test_common.dart';
8+
import 'common/test_helper.dart';
9+
10+
const String shortFile =
11+
'breakpoints_ignore_late_initialization_error_instructions_test.dart';
12+
13+
// AUTOGENERATED START
14+
//
15+
// Update these constants by running:
16+
//
17+
// dart pkg/vm_service/test/update_line_numbers.dart <test.dart>
18+
//
19+
const LINE_A = 33;
20+
const LINE_B = 42;
21+
const LINE_C = 51;
22+
// AUTOGENERATED END
23+
24+
int getThree() => 3;
25+
26+
void testeeMain() {
27+
// ignore: prefer_final_locals
28+
late int x = 1;
29+
// When a late variable is read, the VM performs checks to ensure that the
30+
// variable has been initialized. When a breakpoint is set on the following
31+
// line, it should resolve to the [toDouble] call instruction, not to an
32+
// instruction part of the late variable initialization checks.
33+
final double xd = x.toDouble(); // LINE_A
34+
print(xd);
35+
36+
late final int y = 2;
37+
// When a late final variable is read, the VM performs checks to ensure that
38+
// the variable has been assigned a value exactly once. When a breakpoint is
39+
// set on the following line, it should resolve to the [toDouble] call
40+
// instruction, not to an instruction part of the late variable assignment
41+
// checks.
42+
final double yd = y.toDouble(); // LINE_B
43+
print(yd);
44+
45+
late final int z;
46+
// When a late final variable is assigned a value, the VM performs checks to
47+
// ensure that the variable has not already been initialized. When a
48+
// breakpoint is set on the following line, it should resolve to the
49+
// [getThree] call instruction, not to an instruction part of the late
50+
// variable initialization checks.
51+
z = getThree(); // LINE_C
52+
print(z);
53+
}
54+
55+
List<String> stops = [];
56+
57+
const List<String> expected = [
58+
'$shortFile:$LINE_A:23', // on 'toDouble'
59+
'$shortFile:$LINE_B:23', // on 'toDouble'
60+
'$shortFile:$LINE_C:7', // on 'getThree'
61+
];
62+
63+
final tests = <IsolateTest>[
64+
hasPausedAtStart,
65+
setBreakpointAtLine(LINE_A),
66+
setBreakpointAtLine(LINE_B),
67+
setBreakpointAtLine(LINE_C),
68+
resumeProgramRecordingStops(stops, false),
69+
checkRecordedStops(stops, expected),
70+
];
71+
72+
Future<void> main([args = const <String>[]]) => runIsolateTests(
73+
args,
74+
tests,
75+
shortFile,
76+
testeeConcurrent: testeeMain,
77+
pauseOnStart: true,
78+
pauseOnExit: true,
79+
);

runtime/vm/compiler/frontend/kernel_to_il.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,9 @@ Fragment FlowGraphBuilder::ThrowLateInitializationError(
511511

512512
// Call LateError._throwFoo.
513513
instructions += Constant(name);
514-
instructions += StaticCall(position, throw_new,
515-
/* argument_count = */ 1, ICData::kStatic);
514+
instructions +=
515+
StaticCall(TokenPosition::Synthetic(position.Pos()), throw_new,
516+
/* argument_count = */ 1, ICData::kStatic);
516517
instructions += Drop();
517518

518519
return instructions;

0 commit comments

Comments
 (0)