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