Title: Evaluate expression returns variable value from wrong scope · Issue #1882 · PowerShell/PowerShellEditorServices · GitHub
Open Graph Title: Evaluate expression returns variable value from wrong scope · Issue #1882 · PowerShell/PowerShellEditorServices
X Title: Evaluate expression returns variable value from wrong scope · Issue #1882 · PowerShell/PowerShellEditorServices
Description: 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 scr...
Open Graph Description: 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 # b...
X Description: 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...
Opengraph URL: https://github.com/PowerShell/PowerShellEditorServices/issues/1882
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Evaluate expression returns variable value from wrong scope","articleBody":"### Prerequisites\r\n\r\n- [X] Write a descriptive title.\r\n- [X] Make sure you are able to repro it on the latest version\r\n- [X] Search the existing issues.\r\n\r\n### Steps to reproduce\r\n\r\n```powershell\r\n$myVarName = 123\r\n\u0026 {\r\n $myVarName = 456\r\n $myVarName # breakpoint here\r\n}\r\n```\r\n\r\nWhile 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).\r\n\r\nSimply changing the expression to `$myVarName;` returns the local value (456). This points us in the direction of this method as source of the bug.\r\nhttps://github.com/PowerShell/PowerShellEditorServices/blob/00238cdd8322241276b9691dd96f1f1b860bd1f9/src/PowerShellEditorServices/Services/DebugAdapter/Handlers/DebugEvaluateHandler.cs#L63-L64\r\n\r\nThe evaluate-call in my scenario is made through using `new vscode.InlineValueEvaluatableExpression(range, expression)` which VSCode executes [here](https://github.com/microsoft/vscode/blob/13429c254b99fdc0b1d28056d5fd5e43e95f5c07/src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts#L691-L703)\r\n\r\n### Expected behavior\r\n\r\n`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.\r\n\r\n### Actual behavior\r\n\r\nReturns 123.\r\n\r\nAfter executing `$script:myVarName` or `$global:myVarName` in PSIC and using step over, `evaluate` returns the newest value (no scope-preference/-priority).\r\n\r\nChanging `$myVarName` in PSIC + step over updates variable explorer + `vscode.InlineValueVariableLookup` result, but `evaluate` doesn't care - still showing the latest parent-scope value.\r\n\r\n### Error details\r\n\r\n_No response_\r\n\r\n### Environment data\r\n\r\n```PowerShell\r\nName Value\r\n---- -----\r\nPSVersion 7.1.3\r\nPSEdition Core\r\nGitCommitId 7.1.3\r\nOS Linux 5.10.102.1-microsoft-standard-WSL2 #1 SMP Wed Mar 2 00:30:59 UTC 2022\r\nPlatform Unix\r\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}\r\nPSRemotingProtocolVersion 2.3\r\nSerializationVersion 1.1.0.1\r\nWSManStackVersion 3.0\r\n```\r\n\r\n\r\n### Version\r\n\r\n2022.7.2\r\n\r\n### Visuals\r\n\r\n_No response_","author":{"url":"https://github.com/fflaten","@type":"Person","name":"fflaten"},"datePublished":"2022-08-12T19:28:55.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/1882/PowerShellEditorServices/issues/1882"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d0914e4b-40f4-f6b7-02fb-445d11fb66a6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D5BC:CB9F0:990B24:CD737D:6A581CB5 |
| html-safe-nonce | d78a85e6436018e764538f8c0684dccfe54e529b0ca4ffa4d66e3c9aff147b65 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENUJDOkNCOUYwOjk5MEIyNDpDRDczN0Q6NkE1ODFDQjUiLCJ2aXNpdG9yX2lkIjoiODY5ODg4MTc2MDcxMTY3OTE1NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | b500608ff4d4efcb02c31033fea1d21c02a3cd4b00ec49841b4c07da4d92eebd |
| hovercard-subject-tag | issue:1337632037 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShellEditorServices/1882/issue_layout |
| twitter:image | https://opengraph.githubassets.com/dfc70bc3008806f105dee48dc1234c4ab1aa394afae573d3ec1ceb7493d3a19a/PowerShell/PowerShellEditorServices/issues/1882 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/dfc70bc3008806f105dee48dc1234c4ab1aa394afae573d3ec1ceb7493d3a19a/PowerShell/PowerShellEditorServices/issues/1882 |
| og:image:alt | 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 # b... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | fflaten |
| hostname | github.com |
| expected-hostname | github.com |
| None | 49c8c15fabcbf356d607a90ca115c13b273e42ff8b74155de050fd229a9b0121 |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShellEditorServices git https://github.com/PowerShell/PowerShellEditorServices.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 36031537 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShellEditorServices |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 36031537 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShellEditorServices |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 3fb1f684e7a833eb1b2d01d39875a2b52cb4fe9b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width