Skip to content

Commit eda6e99

Browse files
bkonyiCommit Queue
authored and
Commit Queue
committed
[ Service ] Omit BoundVariables for wildcard variables in service responses
This will prevent wildcard parameters and local variables from appearing in the debugger variables pane. Responses that describe program structure (e.g., function parameters) will continue to report wildcard elements. Fixes #55765 TEST=pkg/vm_service/test/wildcard_test.dart Change-Id: Id546fe177bc734e36f69fa6ed8102ca7e5832ab6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/380340 Reviewed-by: Derek Xu <[email protected]> Reviewed-by: Kallen Tu <[email protected]> Commit-Queue: Ben Konyi <[email protected]>
1 parent 8fbca8b commit eda6e99

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed
+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
// SharedOptions=--enable-experiment=wildcard-variables
6+
7+
// ignore: invalid_language_version_override
8+
// @dart = 3.6
9+
10+
import 'dart:developer';
11+
// Tests wildcard import prefixes.
12+
// ignore: unused_import, library_prefixes, no_leading_underscores_for_library_prefixes
13+
import 'dart:io' as _;
14+
15+
import 'package:test/test.dart';
16+
import 'package:vm_service/vm_service.dart';
17+
18+
import 'common/service_test_common.dart';
19+
import 'common/test_helper.dart';
20+
21+
// ignore: duplicate_definition, avoid_types_as_parameter_names
22+
void foo<_>(i, _, _) {
23+
final int _ = 42;
24+
debugger();
25+
}
26+
27+
void test() {
28+
foo<String>(0, 1, 2);
29+
}
30+
31+
final tests = <IsolateTest>[
32+
hasStoppedAtBreakpoint,
33+
(VmService service, IsolateRef isolateRef) async {
34+
final isolateId = isolateRef.id!;
35+
final isolate = await service.getIsolate(isolateId);
36+
37+
final lib =
38+
await service.getObject(isolateId, isolate.rootLib!.id!) as Library;
39+
final ioImport =
40+
lib.dependencies!.firstWhere((e) => e.target!.name == 'dart.io');
41+
// Wildcard prefixes shouldn't be stripped from imports.
42+
expect(ioImport.prefix, '_');
43+
44+
final stack = await service.getStack(isolateId);
45+
final frame = stack.frames!.first;
46+
final function =
47+
await service.getObject(isolateId, frame.function!.id!) as Func;
48+
expect(function.name, 'foo');
49+
50+
// Type parameter names are replaced with synthetic names in general so we
51+
// don't need to check for the name '_' here.
52+
final typeParameters = function.signature!.typeParameters!;
53+
expect(typeParameters.length, 1);
54+
55+
// There should only be bound variables for non-wildcard parameters.
56+
final vars = frame.vars!;
57+
expect(vars.length, 1);
58+
expect(vars.first.name, 'i');
59+
},
60+
];
61+
62+
void main([args = const <String>[]]) => runIsolateTests(
63+
args,
64+
tests,
65+
'wildcard_test.dart',
66+
testeeConcurrent: test,
67+
experiments: ['wildcard-variables'],
68+
);

runtime/vm/compiler/frontend/scope_builder.cc

+4-1
Original file line numberDiff line numberDiff line change
@@ -1373,7 +1373,7 @@ void ScopeBuilder::VisitVariableDeclaration() {
13731373
variable->set_is_late();
13741374
variable->set_late_init_offset(initializer_offset);
13751375
}
1376-
if (helper.IsSynthesized()) {
1376+
if (helper.IsSynthesized() || helper.IsWildcard()) {
13771377
variable->set_invisible(true);
13781378
}
13791379

@@ -1680,6 +1680,9 @@ void ScopeBuilder::AddVariableDeclarationParameter(
16801680
if (helper.IsCovariant()) {
16811681
variable->set_is_explicit_covariant_parameter();
16821682
}
1683+
if (helper.IsWildcard()) {
1684+
variable->set_invisible(true);
1685+
}
16831686

16841687
const bool needs_covariant_check_in_method =
16851688
helper.IsCovariant() ||

0 commit comments

Comments
 (0)