You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
switch statement report incorrect error position when it fails to evaluate the condition #7150
PS> cat .\about.ps1
$Test=1;
switch ($NeverUsedBefore[0]) {
"a" {};
}
Expected behavior
Run about.ps1 reports the correct script location.
PS> .\about.ps1
Cannot index into a null array.
At F:\tmp\about.ps1:2 char:9
+ switch ($NeverUsedBefore[0]) {
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Actual behavior
Run about.ps1 reports the wrong script location.
PS> .\about.ps1
Cannot index into a null array.
At F:\tmp\about.ps1:1 char:1
+ $Test = 1;
+ ~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Environment data
>$PSVersionTable
Name Value
---------
PSVersion 6.0.1
PSEdition Core
GitCommitId v6.0.1
OS Microsoft Windows 10.0.17134
Platform Win32NT
PSCompatibleVersions {1.0,2.0,3.0,4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Reverted the original fix in #7151. The fix caused a problem in debugging. When stepping over the scripts in debugging mode, the debugger will stop at the switch statement condition expression twice at the very beginning -- one for evaluating the condition, and one for iterating the condition.
Here is an example:
PS:4> .\about.ps1
Entering debug mode. Use h or ? for help.
Hit Line breakpoint on 'F:\tmp\about.ps1:1'
At F:\tmp\about.ps1:1 char:1
+ $Test = 1;
+ ~~~~~~~~~
PS:4>> v
At F:\tmp\about.ps1:2 char:1
+ $b = 1..10
+ ~~~~~~~~~~
PS:4>> v
At F:\tmp\about.ps1:3 char:9
+ switch ($b) {
+ ~~
PS:4>> v
At F:\tmp\about.ps1:3 char:9
+ switch ($b) {
+ ~~
PS:4>> v
At F:\tmp\about.ps1:4 char:5
+ "a" {};
+ ~~~
Activity
iricigor commentedon Jun 23, 2018
Another example, but with
forstatementIt reports an error on line 1. I think wrong error location is reported for the same reason as
switchstatement.daxian-dbw commentedon Jun 26, 2018
Igor (@iricigor) Thanks for the report. I didn't see your comment when merging the PR. Will submit another PR to address the issue with
forloop.daxian-dbw commentedon Jun 26, 2018
Reverted the original fix in #7151. The fix caused a problem in debugging. When stepping over the scripts in debugging mode, the debugger will stop at the switch statement condition expression twice at the very beginning -- one for evaluating the condition, and one for iterating the condition.
Here is an example: