-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Debugger via VM evaluates constructor argument instead of class member #59661
Comments
FYI @derekxu16. Also cc @alexmarkov who might have some insights as to scoping. |
Parameter (local variable)
It looks like front-end is not taking this rule into account when deciding if /cc @johnniwinther |
Is it the case that the same name could be either in the same frame? For example: class A {
final String foo;
final String bar;
A(String foo)
: foo = '', // foo 1
bar = foo; // foo 2
} Something I mentioned in another issue is that it might be useful if we can provide a line/col instead of a string expression when evaluating. It also solves some other issues like: var aaa = 'one';
f() {
var aaa = 'two';
debugger();
} If you stop at |
Although, using line/col only works for hovers, and won't fix this issue if you type |
@jensjoha The normal encoding of the AST does support the special scoping of variables from initializing formals so the error might be introduced when we compute the scope from the AST. |
Thank you for your report and for the reproduction. What happens is this: Compiling this (slightly modified) file: import "dart:developer";
class A {
List list;
A(this.list) {
list = [3];
debugger();
print(list);
}
}
void main() {
A([1, 2]);
} results in this kernel file:
where we see that the constructor As at least @johnniwinther and I have talked about many times, expression compilation is not really - and shouldn't really be - "Dart" - it is and should be something different and/or more. |
Thanks for the explanation of the underlying reason for this behavior. Expanding the capabilities of the debugger expressions to view more than what dart code directly could access seems like an interesting concept. For example, I often wish I had unrestricted access to private variables of objects via debug expressions -- dart code doesn't have access, but the debugger does already via the UI. However, the ability to write (somewhat) complex Dart expressions in the debug console is invaluable (e.g. I often will use Regardless, the "proper" behavior in this context seems obvious to me: Regarding "if it would be worth the effort," I think fixing this seems extremely valuable and important. Debug tooling when switching to a new language takes some getting used to, and many people will instinctively go to the debugger to understand why their code isn't working, especially if they are new to Dart. Seeing the wrong value in a variable in the debugger leaves developers confused and frustrated and may altogether dissuade them from sticking with Dart if they have alternatives under consideration. There's a huge difference between thinking the debugger is practically perfect vs. thinking the debugger shows the wrong information in some contexts. If people don't trust what the debugger is showing them, then they might start regressing to |
Refiling Dart-Code/Dart-Code#5363 here after discussion between @DanTup and @bkonyi
Describe the bug
In some scenarios (see reproduction below), the debugger shows the wrong (a stale, previous) value of a class field. This can make debugging super confusing, since the actual behavior of the code doesn't match what the debugger is showing.
To Reproduce
Here's a simple piece of code that reproduces the issue.
If you put a breakpoint on the
print
statement, you'll see two values oflist
depending on whether it is preceded bythis.
.With mouse-over on
list
in the print statement:With mouse-over on
this.list
, which is the same variable:You can also see something similar going on in the variables window:
The pattern appears to be related to the constructor containing
this.
referencing a field of the class, then whether or not further references to that variable includethis.
or not controls whether you get the latest or a stale value for that variable.The output of the program is as expected:
Expected behavior
Variable values shown by the debugger match reality and are consistent, regardless of whether an unnecessary
this.
is included.Screenshots
(see above)
Please complete the following information:
You can run the Dart: Collect Diagnostic Information command from the VS Code command palette (
F1
) to easily capture this information or provide it manually.See details below:
Workspace Environment
Output from 'dart info'
/usr/lib/dart/bin/dart info
If providing this information as part of reporting a bug, please review the information
below to ensure it only contains things you're comfortable posting publicly.
General info
Project info
The text was updated successfully, but these errors were encountered: