|
| 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 | + ); |
0 commit comments