| // Copyright (c) 2025, 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. |
| |
| /// @assertion We let users use a private name in a named parameter when the |
| /// parameter also initializes or declares a field. The compiler removes the `_` |
| /// from the argument name but keeps it for the corresponding field. |
| /// |
| /// @description Check that private named parameters can be debugged. |
| /// @author sgrekhov22@gmail.com |
| |
| // SharedOptions=--enable-experiment=primary-constructors,private-named-parameters |
| |
| import 'dart:developer'; |
| import 'package:vm_service/vm_service.dart'; |
| |
| import '../../../../pkg/vm_service/test/common/service_test_common.dart'; |
| import '../../../../pkg/vm_service/test/common/test_helper.dart'; |
| import '../Utils/expect.dart'; |
| import 'private_named_parameters_t01_lib.dart' as testee_lib; |
| |
| void main([ |
| args = const <String>[], |
| ]) => IsolateTestHarness('private_named_parameters_t01_lib.dart', args) |
| .hasStoppedAtBreakpoint() |
| .stoppedAtLine('LINE_D') |
| .stepInto() |
| .stoppedAtLine('LINE_E') |
| .stepInto() |
| .stoppedAtLine('LINE_A') |
| .addCustomTest((VmService service, IsolateRef isolateRef) async { |
| final isolateId = isolateRef.id!; |
| final xRef1 = |
| await service.evaluateInFrame(isolateId, 0, '_x') as InstanceRef; |
| Expect.equals("null", xRef1.valueAsString); |
| final xRef2 = |
| await service.evaluateInFrame(isolateId, 0, 'this._x') as InstanceRef; |
| Expect.equals("null", xRef2.valueAsString); |
| }) |
| .stepInto() |
| .addCustomTest((VmService service, IsolateRef isolateRef) async { |
| final isolateId = isolateRef.id!; |
| final xRef1 = |
| await service.evaluateInFrame(isolateId, 0, '_x') as InstanceRef; |
| Expect.equals('xxx', xRef1.valueAsString); |
| final xRef2 = |
| await service.evaluateInFrame(isolateId, 0, 'this._x') as InstanceRef; |
| Expect.equals('xxx', xRef2.valueAsString); |
| final xRef3 = await service.evaluateInFrame(isolateId, 0, 'x'); |
| Expect.isTrue(xRef3 is ErrorRef); |
| final xRef4 = await service.evaluateInFrame(isolateId, 0, 'this.x'); |
| Expect.isTrue(xRef4 is ErrorRef); |
| }) |
| .stepInto() |
| .stoppedAtLine('LINE_F') |
| .stepInto() |
| .stoppedAtLine('LINE_B') |
| .addCustomTest((VmService service, IsolateRef isolateRef) async { |
| final isolateId = isolateRef.id!; |
| final xRef1 = |
| await service.evaluateInFrame(isolateId, 0, '_x') as InstanceRef; |
| Expect.equals("null", xRef1.valueAsString); |
| final xRef2 = |
| await service.evaluateInFrame(isolateId, 0, 'this._x') as InstanceRef; |
| Expect.equals("null", xRef2.valueAsString); |
| }) |
| .stepInto() |
| .addCustomTest((VmService service, IsolateRef isolateRef) async { |
| final isolateId = isolateRef.id!; |
| final xRef1 = |
| await service.evaluateInFrame(isolateId, 0, '_x') as InstanceRef; |
| Expect.equals('yyy', xRef1.valueAsString); |
| final xRef2 = |
| await service.evaluateInFrame(isolateId, 0, 'this._x') as InstanceRef; |
| Expect.equals('yyy', xRef2.valueAsString); |
| final xRef3 = await service.evaluateInFrame(isolateId, 0, 'x'); |
| Expect.isTrue(xRef3 is ErrorRef); |
| final xRef4 = await service.evaluateInFrame(isolateId, 0, 'this.x'); |
| Expect.isTrue(xRef4 is ErrorRef); |
| }) |
| .stepInto() |
| .stoppedAtLine('LINE_G') |
| .stepInto() |
| .stoppedAtLine('LINE_C') |
| .addCustomTest((VmService service, IsolateRef isolateRef) async { |
| final isolateId = isolateRef.id!; |
| final xRef1 = |
| await service.evaluateInFrame(isolateId, 0, '_x') as InstanceRef; |
| Expect.equals("null", xRef1.valueAsString); |
| final xRef2 = |
| await service.evaluateInFrame(isolateId, 0, 'this._x') as InstanceRef; |
| Expect.equals("null", xRef2.valueAsString); |
| final xRef3 = |
| await service.evaluateInFrame(isolateId, 0, '_y') as InstanceRef; |
| Expect.equals("null", xRef3.valueAsString); |
| final xRef4 = |
| await service.evaluateInFrame(isolateId, 0, 'this._y') as InstanceRef; |
| Expect.equals("null", xRef4.valueAsString); |
| }) |
| .stepInto() |
| .addCustomTest((VmService service, IsolateRef isolateRef) async { |
| final isolateId = isolateRef.id!; |
| final xRef1 = |
| await service.evaluateInFrame(isolateId, 0, '_x') as InstanceRef; |
| Expect.equals('1', xRef1.valueAsString); |
| final xRef2 = |
| await service.evaluateInFrame(isolateId, 0, 'this._x') as InstanceRef; |
| Expect.equals('1', xRef2.valueAsString); |
| final xRef3 = |
| await service.evaluateInFrame(isolateId, 0, '_y') as InstanceRef; |
| Expect.equals('null', xRef3.valueAsString); |
| final xRef4 = |
| await service.evaluateInFrame(isolateId, 0, 'this._y') as InstanceRef; |
| Expect.equals('null', xRef3.valueAsString); |
| |
| final xRef5 = await service.evaluateInFrame(isolateId, 0, 'x'); |
| Expect.isTrue(xRef5 is ErrorRef); |
| final xRef6 = await service.evaluateInFrame(isolateId, 0, 'this.x'); |
| Expect.isTrue(xRef6 is ErrorRef); |
| final xRef7 = await service.evaluateInFrame(isolateId, 0, 'y'); |
| Expect.isTrue(xRef7 is ErrorRef); |
| final xRef8 = await service.evaluateInFrame(isolateId, 0, 'this.y'); |
| Expect.isTrue(xRef8 is ErrorRef); |
| }) |
| .stepInto() |
| .addCustomTest((VmService service, IsolateRef isolateRef) async { |
| final isolateId = isolateRef.id!; |
| final xRef1 = |
| await service.evaluateInFrame(isolateId, 0, '_x') as InstanceRef; |
| Expect.equals('1', xRef1.valueAsString); |
| final xRef2 = |
| await service.evaluateInFrame(isolateId, 0, 'this._x') as InstanceRef; |
| Expect.equals('1', xRef2.valueAsString); |
| final xRef3 = |
| await service.evaluateInFrame(isolateId, 0, '_y') as InstanceRef; |
| Expect.equals('2', xRef3.valueAsString); |
| final xRef4 = |
| await service.evaluateInFrame(isolateId, 0, 'this._y') as InstanceRef; |
| Expect.equals('2', xRef3.valueAsString); |
| |
| final xRef5 = await service.evaluateInFrame(isolateId, 0, 'x'); |
| Expect.isTrue(xRef5 is ErrorRef); |
| final xRef6 = await service.evaluateInFrame(isolateId, 0, 'this.x'); |
| Expect.isTrue(xRef6 is ErrorRef); |
| final xRef7 = await service.evaluateInFrame(isolateId, 0, 'y'); |
| Expect.isTrue(xRef7 is ErrorRef); |
| final xRef8 = await service.evaluateInFrame(isolateId, 0, 'this.y'); |
| Expect.isTrue(xRef8 is ErrorRef); |
| }) |
| .run( |
| pauseOnExit: true, |
| extraArgs: [ |
| '--enable-experiment=primary-constructors', |
| '--enable-experiment=private-named-parameters', |
| ], |
| testeeMain: testee_lib.main, |
| ); |