diff --git a/VM/declaring_constructors_t02.dart b/VM/declaring_constructors_t02.dart new file mode 100644 index 0000000000..1f66d663b4 --- /dev/null +++ b/VM/declaring_constructors_t02.dart @@ -0,0 +1,110 @@ +// 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 A declaring constructor declaration is a declaration that +/// contains a `` with a +/// ``, or a declaration that contains a +/// ``, or it is a +/// `` in the header of a class, enum, or extension +/// type declaration, together with a declaration in the body that contains a +/// ``. +/// +/// @description Check that members initialized in primary initializer scope can +/// be debugged. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=declaring-constructors + +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'; + +const String shortFile = 'declaring_constructors_t03.dart'; + +// AUTOGENERATED START +// +// Update these constants by running: +// +// dart pkg/vm_service/test/update_line_numbers.dart tests/co19/src/VM/declaring_constructors_t02.dart +// +const LINE_A = 41; +const LINE_B = 44; +const LINE_C = 48; +const LINE_D = 49; +const LINE_E = 50; +// AUTOGENERATED END + +class C1(var String x); // LINE_A + +class C2 { + this(final String x); // LINE_B +} + +void testeeMain() { + debugger(); // LINE_C + C1("xxx"); // LINE_D + C2("yyy"); // LINE_E +} + +final tests = [ + hasStoppedAtBreakpoint, + stoppedAtLine(LINE_C), + stepInto, + stoppedAtLine(LINE_D), + stepInto, + stoppedAtLine(LINE_A), + (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, + (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); + }, + stepInto, + stoppedAtLine(LINE_E), + stepInto, + stoppedAtLine(LINE_B), + (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, + (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); + }, +]; + +void main([args = const []]) => runIsolateTests( + args, + tests, + 'declaring_constructors_t02.dart', + pauseOnExit: true, + testeeConcurrent: testeeMain, +);