[ 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 https://github.com/dart-lang/sdk/issues/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 <derekx@google.com>
Reviewed-by: Kallen Tu <kallentu@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
diff --git a/pkg/vm_service/test/wildcard_test.dart b/pkg/vm_service/test/wildcard_test.dart
new file mode 100644
index 0000000..7d1ebe5
--- /dev/null
+++ b/pkg/vm_service/test/wildcard_test.dart
@@ -0,0 +1,68 @@
+// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// SharedOptions=--enable-experiment=wildcard-variables
+
+// ignore: invalid_language_version_override
+// @dart = 3.6
+
+import 'dart:developer';
+// Tests wildcard import prefixes.
+// ignore: unused_import, library_prefixes, no_leading_underscores_for_library_prefixes
+import 'dart:io' as _;
+
+import 'package:test/test.dart';
+import 'package:vm_service/vm_service.dart';
+
+import 'common/service_test_common.dart';
+import 'common/test_helper.dart';
+
+// ignore: duplicate_definition, avoid_types_as_parameter_names
+void foo<_>(i, _, _) {
+ final int _ = 42;
+ debugger();
+}
+
+void test() {
+ foo<String>(0, 1, 2);
+}
+
+final tests = <IsolateTest>[
+ hasStoppedAtBreakpoint,
+ (VmService service, IsolateRef isolateRef) async {
+ final isolateId = isolateRef.id!;
+ final isolate = await service.getIsolate(isolateId);
+
+ final lib =
+ await service.getObject(isolateId, isolate.rootLib!.id!) as Library;
+ final ioImport =
+ lib.dependencies!.firstWhere((e) => e.target!.name == 'dart.io');
+ // Wildcard prefixes shouldn't be stripped from imports.
+ expect(ioImport.prefix, '_');
+
+ final stack = await service.getStack(isolateId);
+ final frame = stack.frames!.first;
+ final function =
+ await service.getObject(isolateId, frame.function!.id!) as Func;
+ expect(function.name, 'foo');
+
+ // Type parameter names are replaced with synthetic names in general so we
+ // don't need to check for the name '_' here.
+ final typeParameters = function.signature!.typeParameters!;
+ expect(typeParameters.length, 1);
+
+ // There should only be bound variables for non-wildcard parameters.
+ final vars = frame.vars!;
+ expect(vars.length, 1);
+ expect(vars.first.name, 'i');
+ },
+];
+
+void main([args = const <String>[]]) => runIsolateTests(
+ args,
+ tests,
+ 'wildcard_test.dart',
+ testeeConcurrent: test,
+ experiments: ['wildcard-variables'],
+ );
diff --git a/runtime/vm/compiler/frontend/scope_builder.cc b/runtime/vm/compiler/frontend/scope_builder.cc
index 6bcf763..fa54fde 100644
--- a/runtime/vm/compiler/frontend/scope_builder.cc
+++ b/runtime/vm/compiler/frontend/scope_builder.cc
@@ -1373,7 +1373,7 @@
variable->set_is_late();
variable->set_late_init_offset(initializer_offset);
}
- if (helper.IsSynthesized()) {
+ if (helper.IsSynthesized() || helper.IsWildcard()) {
variable->set_invisible(true);
}
@@ -1680,6 +1680,9 @@
if (helper.IsCovariant()) {
variable->set_is_explicit_covariant_parameter();
}
+ if (helper.IsWildcard()) {
+ variable->set_invisible(true);
+ }
const bool needs_covariant_check_in_method =
helper.IsCovariant() ||