-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Semantic model should use the first non-empty token of statement to determine binder #16505
Conversation
b20f6bb
to
d4ab4ec
Compare
@dotnet/roslyn-compiler for review please (RTM bug). |
@@ -1172,6 +1172,15 @@ protected int GetAdjustedNodePosition(SyntaxNode node) | |||
|
|||
var fullSpan = this.Root.FullSpan; | |||
var position = node.SpanStart; | |||
if (node is StatementSyntax) |
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.
Why is this specific to statements?
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.
Please either relax this condition (so it applies unconditionally), or file a new issue to relax this in milestone 2.1.
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.
Filed follow-up issue: #16558
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, other than the one comment.
@dotnet/roslyn-compiler for a second review please (RTM). |
@MattGertz for ask mode approval. |
Was approved by shiproom. |
Customer scenario
While the user is editing, some bad code that includes some declaration expression will cause the semantic model to throw. This causes VS to crash.
In the following example,
GetSymbolInfo
onx
triggers binding of the embedded statement, but that would have failed because the wrong binder was used.Bugs this fixes:
Fixes https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems?id=363727
Workarounds, if any
Valid code would not cause this problem. Also, any variant of the code that doesn't cause a missing token to be parsed on the second line (for example, deleting
&&
).Risk
The risk is low. The fix was kept tight to minimize risk. Only statements will get this adjustment and only empty tokens are skipped.
Performance impact
Low. The additional computation is negligible.
Is this a regression from a previous update?
No. This was already broken in RC.2 and I think all the way back in June.
Root cause analysis:
The wrong binder was picked because the embedded statement is parsed as a missing token (at the start of the second line), followed by
&&
(with the spaces attached as trivia). The various adjustments of the position for finding the binder would result in the closing paren of the first line to be selected. Now, the position of the&&
is selected (the syntax with zero-width within a statement is ignored).How was the bug found?
Watson crash.
@dotnet/roslyn-compiler for review.