|
| 1 | +// Copyright (c) 2025, 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 | +/// @assertion Consider an expression `e` which is a member invocation with |
| 6 | +/// syntactic receiver `C` and an associated member name `m`. Assume that `m` is |
| 7 | +/// a static member declared by `D`. The static analysis and dynamic semantics |
| 8 | +/// of this expression is the same as in Dart before the introduction of this |
| 9 | +/// feature. |
| 10 | +/// ... |
| 11 | +/// Assume that it is an extension `E` that declares a static member named `m`. |
| 12 | +/// The invocation is then treated as `E.m()`. |
| 13 | +/// |
| 14 | +/// @description Check that `C.m()` is treated as `E.m()`. |
| 15 | + |
| 16 | +
|
| 17 | +// SharedOptions=--enable-experiment=static-extensions |
| 18 | + |
| 19 | +import 'dart:developer'; |
| 20 | +import 'package:vm_service/vm_service.dart'; |
| 21 | + |
| 22 | +import '../../../../pkg/vm_service/test/common/service_test_common.dart'; |
| 23 | +import '../../../../pkg/vm_service/test/common/test_helper.dart'; |
| 24 | +import '../Utils/expect.dart'; |
| 25 | + |
| 26 | +class C {} |
| 27 | + |
| 28 | +extension ExtC on C { |
| 29 | + static String foo() => "ExtC"; |
| 30 | +} |
| 31 | + |
| 32 | +void testeeMain() { |
| 33 | + debugger(); |
| 34 | +} |
| 35 | + |
| 36 | +final tests = <IsolateTest>[ |
| 37 | + hasStoppedAtBreakpoint, |
| 38 | + |
| 39 | + // Test interaction of expression evaluation with static extensions. |
| 40 | + (VmService service, IsolateRef isolateRef) async { |
| 41 | + final isolateId = isolateRef.id!; |
| 42 | + |
| 43 | + InstanceRef response = |
| 44 | + await service.evaluateInFrame(isolateId, 0, 'C.foo()') as InstanceRef; |
| 45 | + Expect.equals('ExtC', response.valueAsString); |
| 46 | + }, |
| 47 | +]; |
| 48 | + |
| 49 | +void main([args = const <String>[]]) => runIsolateTests( |
| 50 | + args, |
| 51 | + tests, |
| 52 | + 'static_extensions_t01.dart', |
| 53 | + pauseOnExit: true, |
| 54 | + testeeConcurrent: testeeMain, |
| 55 | +); |
0 commit comments