Repository navigation
Fix error position for switch-statement condition and for-statement initializer - #7305
Conversation
…tatement initializer
| } | ||
|
|
||
| internal Expression UpdatePosition(Ast ast) | ||
| private int AddSequencePoint(IScriptExtent extent) |
There was a problem hiding this comment.
Note: this method is added to make sure that one extent can only be added to the sequence list once.
|
Bruce Payette (@BrucePay) Can you please review this PR when you have time? Thanks! |
| $errorRecord.ScriptStackTrace | Should -Match "SwitchError2.ps1: line 3" | ||
| } | ||
|
|
||
| It "for statement initializer evaluation failure should report correct error position" { |
There was a problem hiding this comment.
There should also be a test for while/do loops
There was a problem hiding this comment.
More tests added.
|
|
||
| $script3 = @' | ||
| $test = 2 | ||
| for ("string".Length; |
There was a problem hiding this comment.
In the product code, there's a special check for while/do loops, but I don't see a test here for that?
There was a problem hiding this comment.
More test added.
|
Steve Lee (@SteveL-MSFT) I corrected the condition sequence point update for while/do-while/do-until loops and if-statement as well. More tests are added. Please take another look when you have time. Thanks! |
Paul Higinbotham (PaulHigin)
left a comment
There was a problem hiding this comment.
LGTM
| } | ||
| else | ||
| { | ||
| // For switch statement, we don't want the debugger to stop at 'stmt.Condition' before evaluating it. |
There was a problem hiding this comment.
From this comment it is not clear how the code prevents these two undesirable behaviors. Can you clarify?
There was a problem hiding this comment.
The argument checkBreakpoints: false when calling UpdatePositionExpr means not checking breaking point for this sequence point update.
| "line 1" | ||
| "line 2" | ||
| "line 3" | ||
| $path = Setup -PassThru -File BasicTest.ps1 -Content $script |
There was a problem hiding this comment.
Should we add debugger stop position tests as well as hit count (similar to error position tests)?
There was a problem hiding this comment.
That sounds good. Can you please show an example of how to check for debugger stop position?
There was a problem hiding this comment.
You can create a type (Add-Type) that has a method to handle the runspace.debugger.DebuggerStop event and then check the event argument InvocationInfo extent (I think). Contact me offline for more info.
There was a problem hiding this comment.
OK. I will play with it, and add more tests in a separate PR. Thanks!
…tatements (PowerShell#7305) - Make switch-statement report correct error position when it fails to evaluate the condition. - Make for-statement report correct error position when it fails to evaluate the initializer. - For the condition of `if/for/while/do-while/do-until` statements, the sequence point update is either duplicate in some cases (for `if/for/while`) which causes debugger to stop at the condition twice before moving forward, or missing (for `do-while/do-until`) which causes debugger to skip the condition. They are fixed.
PR Summary
Fix #7150
Before:
After:
Break point check
For switch-statement condition, retain the same behavior as is:
Script Content
For for-statement initializer, fix the incorrect breaking point position when the initializer is a simple command expression:
Script Content
Before:
After:
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:to the beginning of the title and remove the prefix when the PR is ready.[feature]if the change is significant or affects feature tests