Fix error position for switch-statement condition and for-statement initializer#7305
Fix error position for switch-statement condition and for-statement initializer#7305daxian-dbw merged 2 commits intoPowerShell:masterfrom
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.
|
@BrucePay Can you please review this PR when you have time? Thanks! |
There was a problem hiding this comment.
There should also be a test for while/do loops
|
|
||
| $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?
|
@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! |
| } | ||
| 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!
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