Skip to content
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

Merged
merged 1 commit into from
Jan 19, 2017

Conversation

jcouv
Copy link
Member

@jcouv jcouv commented Jan 14, 2017

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 on x triggers binding of the embedded statement, but that would have failed because the wrong binder was used.

if(true)
            && int.TryParse(x, out int y)) id(iVal);

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.

@jcouv jcouv added this to the 2.0 (RTM) milestone Jan 14, 2017
@jcouv jcouv self-assigned this Jan 14, 2017
@jcouv
Copy link
Member Author

jcouv commented Jan 17, 2017

@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)
Copy link
Member

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?

Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member

@gafter gafter left a 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.

@jcouv
Copy link
Member Author

jcouv commented Jan 18, 2017

@dotnet/roslyn-compiler for a second review please (RTM).

@jcouv
Copy link
Member Author

jcouv commented Jan 19, 2017

@MattGertz for ask mode approval.

@jcouv
Copy link
Member Author

jcouv commented Jan 19, 2017

Was approved by shiproom.

@jcouv jcouv merged commit e9ef4e0 into dotnet:master Jan 19, 2017
@jcouv jcouv deleted the outvar-semcrash branch January 19, 2017 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants