Skip to content

Commit f9f7b29

Browse files
jensjohaCommit Queue
authored andcommitted
[VM] Mark initializing formal variables as invisible
Fixes #59661 Tested: pkg/vm_service/test/issue_59661.dart and existing tests. Change-Id: I09f708dabfeb71ae8aa078d73fc23295562a451c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/399900 Commit-Queue: Jens Johansen <[email protected]> Reviewed-by: Ben Konyi <[email protected]>
1 parent 5236641 commit f9f7b29

File tree

3 files changed

+151
-2
lines changed

3 files changed

+151
-2
lines changed
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
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+
import 'dart:developer';
6+
import 'package:test/test.dart';
7+
import 'package:vm_service/vm_service.dart';
8+
import 'common/service_test_common.dart';
9+
import 'common/test_helper.dart';
10+
11+
// AUTOGENERATED START
12+
//
13+
// Update these constants by running:
14+
//
15+
// dart pkg/vm_service/test/update_line_numbers.dart <test.dart>
16+
//
17+
const LINE_CLASS_A = 29;
18+
const LINE_CLASS_A_NAMED = 34;
19+
const LINE_CLASS_A_NAMED2_BREAK_1 = 40;
20+
const LINE_CLASS_A_NAMED2_BREAK_2 = 43;
21+
const LINE_CLASS_A_NAMED2_BREAK_3 = 46;
22+
const LINE_CLASS_B = 55;
23+
// AUTOGENERATED END
24+
25+
class A {
26+
List list;
27+
A(this.list) {
28+
list = [3];
29+
debugger(); // LINE_CLASS_A
30+
print(list);
31+
}
32+
A.named(this.list) {
33+
list = [4];
34+
debugger(); // LINE_CLASS_A_NAMED
35+
print(list);
36+
}
37+
A.named2(this.list) {
38+
{
39+
final list = [5];
40+
debugger(); // LINE_CLASS_A_NAMED2_BREAK_1
41+
print(list);
42+
}
43+
debugger(); // LINE_CLASS_A_NAMED2_BREAK_2
44+
print(list);
45+
list = [6];
46+
debugger(); // LINE_CLASS_A_NAMED2_BREAK_3
47+
print(list);
48+
}
49+
A.noDebugger(this.list);
50+
}
51+
52+
class B extends A {
53+
B(super.list) : super.noDebugger() {
54+
list = [7];
55+
debugger(); // LINE_CLASS_B
56+
print(list);
57+
}
58+
}
59+
60+
void code() {
61+
A([1, 2]);
62+
A.named([1, 2]);
63+
A.named2([1, 2]);
64+
B([1, 2]);
65+
}
66+
67+
Future<void> Function(VmService, IsolateRef) test(
68+
String topFrameName,
69+
List<String> availableVariables,
70+
List<(String evaluate, String evaluationResult)> evaluations,
71+
) {
72+
return (VmService service, IsolateRef isolateRef) async {
73+
final isolateId = isolateRef.id!;
74+
final stack = await service.getStack(isolateId);
75+
76+
// Make sure we are in the right place.
77+
expect(stack.frames!.length, greaterThanOrEqualTo(1));
78+
expect(stack.frames![0].function!.name, topFrameName);
79+
80+
// Check variables.
81+
expect(
82+
(stack.frames![0].vars ?? []).map((v) => v.name).toList(),
83+
equals(availableVariables),
84+
);
85+
86+
// Evaluate.
87+
for (final (expression, expectedResult) in evaluations) {
88+
final dynamic result = await service.evaluateInFrame(
89+
isolateId,
90+
/* frame = */ 0,
91+
expression,
92+
);
93+
print(result.valueAsString);
94+
expect(result.valueAsString, equals(expectedResult));
95+
}
96+
};
97+
}
98+
99+
final tests = <IsolateTest>[
100+
hasStoppedAtBreakpoint,
101+
stoppedAtLine(LINE_CLASS_A),
102+
test('A', ['this'], [('list.toString()', '[3]')]),
103+
resumeIsolate,
104+
hasStoppedAtBreakpoint,
105+
stoppedAtLine(LINE_CLASS_A_NAMED),
106+
test('A.named', ['this'], [('list.toString()', '[4]')]),
107+
resumeIsolate,
108+
hasStoppedAtBreakpoint,
109+
stoppedAtLine(LINE_CLASS_A_NAMED2_BREAK_1),
110+
test(
111+
'A.named2',
112+
['this', 'list'],
113+
[
114+
('list.toString()', '[5]'),
115+
('this.list.toString()', '[1, 2]'),
116+
],
117+
),
118+
resumeIsolate,
119+
hasStoppedAtBreakpoint,
120+
stoppedAtLine(LINE_CLASS_A_NAMED2_BREAK_2),
121+
test('A.named2', ['this'], [('list.toString()', '[1, 2]')]),
122+
resumeIsolate,
123+
hasStoppedAtBreakpoint,
124+
stoppedAtLine(LINE_CLASS_A_NAMED2_BREAK_3),
125+
test('A.named2', ['this'], [('list.toString()', '[6]')]),
126+
resumeIsolate,
127+
hasStoppedAtBreakpoint,
128+
stoppedAtLine(LINE_CLASS_B),
129+
test('B', ['this'], [('list.toString()', '[7]')]),
130+
];
131+
132+
void main([args = const <String>[]]) => runIsolateTests(
133+
args,
134+
tests,
135+
'issue_59661.dart',
136+
testeeConcurrent: code,
137+
pauseOnStart: false,
138+
pauseOnExit: true,
139+
);

runtime/vm/compiler/frontend/kernel_translation_helper.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ class VariableDeclarationHelper {
412412
kFinal = 1 << 0,
413413
kConst = 1 << 1,
414414
kHasDeclaredInitializer = 1 << 2,
415+
kIsInitializingFormal = 1 << 3,
415416
kIsGenericCovariantImpl = 1 << 4,
416417
kLate = 1 << 5,
417418
kRequired = 1 << 6,
@@ -420,6 +421,7 @@ class VariableDeclarationHelper {
420421
kSynthesized = 1 << 9,
421422
kHoisted = 1 << 10,
422423
kWildcard = 1 << 11,
424+
kIsSuperInitializingFormal = 1 << 12,
423425
};
424426

425427
explicit VariableDeclarationHelper(KernelReaderHelper* helper)
@@ -442,6 +444,12 @@ class VariableDeclarationHelper {
442444
bool IsSynthesized() const { return (flags_ & kSynthesized) != 0; }
443445
bool IsHoisted() const { return (flags_ & kHoisted) != 0; }
444446
bool IsWildcard() const { return (flags_ & kWildcard) != 0; }
447+
bool IsInitializingFormal() const {
448+
return (flags_ & kIsInitializingFormal) != 0;
449+
}
450+
bool IsSuperInitializingFormal() const {
451+
return (flags_ & kIsSuperInitializingFormal) != 0;
452+
}
445453
bool HasDeclaredInitializer() const {
446454
return (flags_ & kHasDeclaredInitializer) != 0;
447455
}

runtime/vm/compiler/frontend/scope_builder.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,8 @@ void ScopeBuilder::VisitVariableDeclaration() {
14081408
variable->set_is_late();
14091409
variable->set_late_init_offset(initializer_offset);
14101410
}
1411-
if (helper.IsSynthesized() || helper.IsWildcard()) {
1411+
if (helper.IsSynthesized() || helper.IsWildcard() ||
1412+
helper.IsInitializingFormal() || helper.IsSuperInitializingFormal()) {
14121413
variable->set_invisible(true);
14131414
}
14141415

@@ -1715,7 +1716,8 @@ void ScopeBuilder::AddVariableDeclarationParameter(
17151716
if (helper.IsCovariant()) {
17161717
variable->set_is_explicit_covariant_parameter();
17171718
}
1718-
if (helper.IsWildcard()) {
1719+
if (helper.IsWildcard() || helper.IsInitializingFormal() ||
1720+
helper.IsSuperInitializingFormal()) {
17191721
variable->set_invisible(true);
17201722
}
17211723

0 commit comments

Comments
 (0)