Skip to content

Debugger via VM evaluates constructor argument instead of class member #59661

@mkorbel1

Description

@mkorbel1

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.

class A {
  List list;
  A(this.list) {
    this.list = [3];

    print(list);
  }
}

void main() {
  A([1, 2]);
}

If you put a breakpoint on the print statement, you'll see two values of list depending on whether it is preceded by this..

With mouse-over on list in the print statement:

image

With mouse-over on this.list, which is the same variable:

image

You can also see something similar going on in the variables window:

image

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 include this. or not controls whether you get the latest or a stale value for that variable.

The output of the program is as expected:

[3]

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.

  • Operating System and version: Windows 11 + WSL
  • VS Code version: 1.95.3
  • Dart extension version: v3.102.0
  • Dart/Flutter SDK version: 3.5.4 (stable) (None) on "linux_x64", no Flutter
  • Target device (if the issue relates to Flutter debugging):

See details below:

Workspace Environment
Dart Code extension: 3.102.0

App: Visual Studio Code
App Host: desktop
Remote: wsl
Host Kind: wsl
Version: linux 1.95.3

Workspace type: Dart (LSP)
Workspace name: thislist [WSL: Ubuntu]

Dart (3.5.4): /usr/lib/dart
Flutter (undefined): undefined (No device)
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

  • sdk constraint: '^3.5.4'
  • dependencies:
  • dev_dependencies: lints, test

Metadata

Metadata

Assignees

Labels

area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.cfe-expression-compilationIssues related to expression compilation in the CFElegacy-area-front-endLegacy: Use area-dart-model instead.triagedIssue has been triaged by sub team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions