Skip to content

Evaluate expression returns variable value from wrong scope #1882

Open
@fflaten

Description

@fflaten

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest version
  • Search the existing issues.

Steps to reproduce

$myVarName = 123
& {
    $myVarName = 456
    $myVarName           # breakpoint here
}

While debugging the script above and stopped at line 4 ($myVarName), evaluate debugger call using context: 'watch', expression: '$myVarName' returns the value from parent scope (123).

Simply changing the expression to $myVarName; returns the local value (456). This points us in the direction of this method as source of the bug.

// First check to see if the watch expression refers to a naked variable reference.
result = _debugService.GetVariableFromExpression(request.Expression);

The evaluate-call in my scenario is made through using new vscode.InlineValueEvaluatableExpression(range, expression) which VSCode executes here

Expected behavior

evaluate should return the local value (456). The local value is shown in Variable Explorer, PSIC and by inline using vscode.InlineValueVariableLookup while stopped at the same location.

Actual behavior

Returns 123.

After executing $script:myVarName or $global:myVarName in PSIC and using step over, evaluate returns the newest value (no scope-preference/-priority).

Changing $myVarName in PSIC + step over updates variable explorer + vscode.InlineValueVariableLookup result, but evaluate doesn't care - still showing the latest parent-scope value.

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.1.3
PSEdition                      Core
GitCommitId                    7.1.3
OS                             Linux 5.10.102.1-microsoft-standard-WSL2 #1 SMP Wed Mar 2 00:30:59 UTC 2022
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Version

2022.7.2

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions