Skip to content

Debugger shows stale value sometimes when this is omitted -- differs from actual value #5363

Closed

Description

@mkorbel1

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

Activity

  1. DanTup commented on Dec 4, 2024

    @DanTup
    Member

    @bkonyi does this look like a VM issue? We're using evaluateInFrame here and I think it's evaluating list as the argument (which is only valid in the initializer?) instead of the class member that the code actually refers to.

    (this may be another place that using line/col described in #5362 (comment) could help?)

  2. added
    in debuggingRelates to the debug adapter or process of running debug sessions
    on Dec 4, 2024
  3. bkonyi commented on Dec 4, 2024

    @bkonyi

    It's definitely evaluating the constructor argument rather than the class member. This could be a VM issue, so I think it's worth filing an issue with the SDK and cc'ing me so I can pull in people more familiar with this logic to look into what's going on.

  4. DanTup commented on Dec 4, 2024

    @DanTup
    Member

    @bkonyi thanks!

    @mkorbel1 do you want to raise this at https://github.com/dart-lang/sdk/issues/new/choose so you're the author, and we'll close this one?

  5. mkorbel1 commented on Dec 4, 2024

    @mkorbel1
    Author

    Thanks for the fast responses! Refiled here: dart-lang/sdk#59661 and closing this one

  6. added this to the v3.104.0 milestone on Dec 11, 2024
  7. added
    in debuggingRelates to the debug adapter or process of running debug sessions
    on Dec 11, 2024
  8. added
    relies on sdk changesSomething that requires changes in the Dart/Flutter SDK to ship before it will become available
    on Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixed in dart / flutterin debuggingRelates to the debug adapter or process of running debug sessionsis bugrelies on sdk changesSomething that requires changes in the Dart/Flutter SDK to ship before it will become available

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions