PowerShellEditorServices icon indicating copy to clipboard operation
PowerShellEditorServices copied to clipboard

Evaluate expression returns variable value from wrong scope

Open fflaten opened this issue 3 years ago • 0 comments

Prerequisites

  • [X] Write a descriptive title.
  • [X] Make sure you are able to repro it on the latest version
  • [X] 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. https://github.com/PowerShell/PowerShellEditorServices/blob/00238cdd8322241276b9691dd96f1f1b860bd1f9/src/PowerShellEditorServices/Services/DebugAdapter/Handlers/DebugEvaluateHandler.cs#L63-L64

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

fflaten avatar Aug 12 '22 19:08 fflaten