-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Fix error position for switch-statement condition and for-statement initializer #7305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…tatement initializer
| } | ||
|
|
||
| internal Expression UpdatePosition(Ast ast) | ||
| private int AddSequencePoint(IScriptExtent extent) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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! |
| $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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should also be a test for while/do loops
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More tests added.
|
|
||
| $script3 = @' | ||
| $test = 2 | ||
| for ("string".Length; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More test added.
|
@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! |
PaulHigin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add debugger stop position tests as well as hit count (similar to error position tests)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds good. Can you please show an example of how to check for debugger stop position?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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