PowerShell / PowerShellEditorServices

A common platform for PowerShell development support in any editor or application!
MIT License
637 stars 219 forks source link

When the built-in `$null` was watched its value was incorrect #2097

Closed andyleejordan closed 11 months ago

andyleejordan commented 1 year ago

No idea why its value was "", but it was, so we special case it and return $null just like you get from watched variables that were assigned the built-in $null.

Resolves https://github.com/PowerShell/vscode-powershell/issues/4816.

andyleejordan commented 1 year ago

image

Tada!

thegraffix commented 1 year ago

Just curious - does this PR address other cases in which $null -eq $var == $true in the WATCH list as well? The built-in $null: "" wasn't the only case in which a null value was represented as an empty string "" e.g. an unitilialized variable should be shown as $VarThatDoesNotExist: $null and not $VarThatDoesNotExist: "".

andyleejordan commented 1 year ago

Hm, I hadn't tried $VarThatDoesNotExist and it wasn't in the issue, so probably not. I can take a look. Anything else you know about?

thegraffix commented 1 year ago

Ha no problem - $VarThatDoesNotExist is actually mentioned in the first bullet point of the issue and also in the screenshot. When debugging a PowerShell script, I would except all cases where $null -eq XYZ == $true would show XYZ: $null in the WATCH pane -- rather than sometimes XYZ: $null and other times XYZ: "". There's some MS Learn documentation on some of the subtleties of evaluating $null.

andyleejordan commented 11 months ago

Ok I took another look at this and now not only do I have answer as to why $null was being evaluated to "", I fixed the root cause 🥳

image