-
Notifications
You must be signed in to change notification settings - Fork 28
#3203. Add VM - CFE interaction tests for declaring constructors #3356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| // 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 `<declaringConstructorSignature>` with a | ||
| /// `<declaringParameterList>`, or a declaration that contains a | ||
| /// `<declaringConstantConstructorSignature>`, or it is a | ||
| /// `<primaryConstructorNoConst>` in the header of a class, enum, or extension | ||
| /// type declaration, together with a declaration in the body that contains a | ||
| /// `<declaringConstructorSignature>`. | ||
| /// | ||
| /// @description Check that declaring constructors invocation and declaration | ||
| /// can be debugged. | ||
| /// @author [email protected] | ||
|
|
||
| // 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_t01.dart'; | ||
|
|
||
| // AUTOGENERATED START | ||
| // | ||
| // Update these constants by running: | ||
| // | ||
| // dart pkg/vm_service/test/update_line_numbers.dart tests/co19/src/VM/declaring_constructors_t01.dart | ||
| // | ||
| const LINE_A = 44; | ||
| const LINE_B = 47; | ||
| const LINE_C = 53; | ||
| const LINE_D = 59; | ||
| const LINE_E = 64; | ||
| const LINE_F = 65; | ||
| const LINE_G = 66; | ||
| const LINE_H = 67; | ||
| // AUTOGENERATED END | ||
|
|
||
| class C1(var int v1, final int v2); // LINE_A | ||
|
|
||
| class C2 { | ||
| this(var int v1, final int v2); // LINE_B | ||
| } | ||
|
|
||
| class C3(int v1, int v2) { | ||
| int v1; | ||
| final int v2; | ||
| this: v1 = v1, v2 = v2; // LINE_C | ||
| } | ||
|
|
||
| class C4 { | ||
| int v1; | ||
| final int v2; | ||
| this(int v1, int v2) : v1 = v1, v2 = v2; // LINE_D | ||
| } | ||
|
|
||
| void testeeMain() { | ||
| debugger(); | ||
| var c1 = C1(1, 2); // LINE_E | ||
| var c2 = C2(3, 4); // LINE_F | ||
| var c3 = C3(5, 6); // LINE_G | ||
| var c4 = C4(7, 8); // LINE_H | ||
| } | ||
|
|
||
| List<String> stops = []; | ||
|
|
||
| const List<String> expected = [ | ||
| '$shortFile:$LINE_E:10', // on '=' | ||
| '$shortFile:$LINE_E:12', // on 'C1' | ||
| '$shortFile:$LINE_A:32', // on 'v2' | ||
| '$shortFile:$LINE_A:35', // on ';' | ||
| '$shortFile:$LINE_F:10', // on '=' | ||
| '$shortFile:$LINE_F:12', // on 'C2' | ||
| '$shortFile:$LINE_B:30', // on 'v2' | ||
| '$shortFile:$LINE_B:33', // on ';' | ||
| '$shortFile:$LINE_G:10', // on '=' | ||
| '$shortFile:$LINE_G:12', // on 'C3' | ||
| '$shortFile:$LINE_C:18', // on 'v2' | ||
| '$shortFile:$LINE_C:25', // on ';' | ||
| '$shortFile:$LINE_H:10', // on '=' | ||
| '$shortFile:$LINE_H:12', // on 'C4' | ||
| '$shortFile:$LINE_D:35', // on 'v2' | ||
| '$shortFile:$LINE_D:42', // on ';' | ||
| ]; | ||
|
|
||
| final tests = <IsolateTest>[ | ||
| hasStoppedAtBreakpoint, | ||
|
|
||
| // Test interaction of expression evaluation with declaring constructors invocation | ||
| (VmService service, IsolateRef isolateRef) async { | ||
| final isolateId = isolateRef.id!; | ||
|
|
||
| InstanceRef response = | ||
| await service.evaluateInFrame(isolateId, 0, 'C1(1, 2).v1') | ||
| as InstanceRef; | ||
| Expect.equals('1', response.valueAsString); | ||
|
|
||
| response = | ||
| await service.evaluateInFrame(isolateId, 0, 'C2(3, 4).v2') | ||
| as InstanceRef; | ||
| Expect.equals('4', response.valueAsString); | ||
|
|
||
| response = | ||
| await service.evaluateInFrame(isolateId, 0, 'C3(5, 6).v1') | ||
| as InstanceRef; | ||
| Expect.equals('5', response.valueAsString); | ||
|
|
||
| response = | ||
| await service.evaluateInFrame(isolateId, 0, 'C4(7, 8).v2') | ||
| as InstanceRef; | ||
| Expect.equals('8', response.valueAsString); | ||
| }, | ||
|
|
||
| // Test interaction of breakpoints with declaring constructors. | ||
| (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 scriptId = lib.scripts!.first.id!; | ||
|
|
||
| var breakpoint = await service.addBreakpoint(isolateId, scriptId, LINE_E); | ||
| var (_, (line, column)) = await breakpoint.getLocation(service, isolateRef); | ||
| Expect.isTrue(breakpoint.enabled); | ||
| Expect.equals(LINE_E, line); | ||
| Expect.equals(10, column); // on '=' | ||
|
|
||
| breakpoint = await service.addBreakpoint(isolateId, scriptId, LINE_F); | ||
| var (_, (line, column)) = await breakpoint.getLocation(service, isolateRef); | ||
| Expect.isTrue(breakpoint.enabled); | ||
| Expect.equals(LINE_F, line); | ||
| Expect.equals(10, column); // on '=' | ||
| await service.removeBreakpoint(isolateId, breakpoint.id!); | ||
|
|
||
| breakpoint = await service.addBreakpoint(isolateId, scriptId, LINE_G); | ||
| var (_, (line, column)) = await breakpoint.getLocation(service, isolateRef); | ||
| Expect.isTrue(breakpoint.enabled); | ||
| Expect.equals(LINE_G, line); | ||
| Expect.equals(10, column); // on '=' | ||
| await service.removeBreakpoint(isolateId, breakpoint.id!); | ||
|
|
||
| breakpoint = await service.addBreakpoint(isolateId, scriptId, LINE_H); | ||
| var (_, (line, column)) = await breakpoint.getLocation(service, isolateRef); | ||
| Expect.isTrue(breakpoint.enabled); | ||
| Expect.equals(LINE_H, line); | ||
| Expect.equals(10, column); // on '=' | ||
| await service.removeBreakpoint(isolateId, breakpoint.id!); | ||
| }, | ||
|
|
||
| // Test interaction of single-stepping with declaring constructors. | ||
| runStepIntoThroughProgramRecordingStops(stops), | ||
| checkRecordedStops(stops, expected), | ||
| ]; | ||
|
|
||
| void main([args = const <String>[]]) => runIsolateTests( | ||
| args, | ||
| tests, | ||
| 'declaring_constructors_t01.dart', | ||
| pauseOnExit: true, | ||
| testeeConcurrent: testeeMain, | ||
| ); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When stopped at this breakpoint, do we expect to see any variables in scope and would they be named v1 and v2?
The new scoping of these constructors has me curious. It might be worth testing in another set of tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This depends on the column number: The current scope for the class header is in general the library scope (or the formal type parameter scope, if there is one), but the current scope for the formal parameters of a primary constructor is the body scope, even though it is located outside the class body.
I suppose the only situation where a breakpoint could be encountered for code in the class header must be the situation where the primary constructor is currently being executed. So the constructor parameters
v1andv2are in scope, but the instance variablesv1andv2are shadowed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nshahan, does this give rise to further comments from you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that the answer is "Yes". @eernstg please confirm.
I'll try to add debugger tests for the primary initializer scope in another PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're at a breakpoint where the currently executing code is the primary constructor then the formal parameters of the primary constructor should be in scope (and hence, presumably, they should be shown). There may or may not be support for showing parts of the state which is not available to code (e.g., the instance variables
v1andv2are shadowed by the formal parameters, and they are not accessible before the initializing formals and/or initializer list etc of the primary constructor have been executed, only when the body is running, if any, but at that time the scope is definitely in the body of the constructor which is syntactically located in the body of the class).