-
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
Improve error tolerance when parsing invalid implicit arrays. #24706
Conversation
tagging @gafter @dotnet/roslyn-compiler |
1a870aa
to
7c8adaf
Compare
commas.Add(this.EatToken()); | ||
if (this.IsPossibleExpression()) | ||
{ | ||
var size = this.AddError(this.ParseExpressionCore(), ErrorCode.ERR_InvalidArray); |
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.
💯 If you don't mind I incorporate this line in the stackalloc inits PR
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.
i would mind that greatly. roslyn is built on non-cooperation, and it should stay that way.
@@ -435,27 +435,26 @@ public void F(int dimension) | |||
} | |||
"; | |||
string expectedOperationTree = @" | |||
IArrayCreationOperation (OperationKind.ArrayCreation, Type: System.Int32[], IsInvalid) (Syntax: 'new[2]/*</bind>*/') |
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.
this used to be the case because we'd parse "new [2]" as "new [] { 2 }" (with lots of missing tokens). The new parse is "new [] { }" (with '2' as skipped text), so we get semantic changes as well.
@jcouv Could i get a review? Also, i'm not sure, but i think Neal said he doesn't see these unless he's tagged as a reviewer. But i can't add reviewers. Could you do that for me? Thanks! |
I wonder what would be the expected behavior for |
Could target |
@CyrusNajmabadi I'm subscribed to the whole Roslyn repo, so I'm drinking from the firehose now. |
@@ -10600,13 +10600,31 @@ private ImplicitArrayCreationExpressionSyntax ParseImplicitlyTypedArrayCreation( | |||
var commas = _pool.Allocate(); | |||
try | |||
{ | |||
while (this.CurrentToken.Kind == SyntaxKind.CommaToken) | |||
while (true) |
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.
We had some parsing bugs with "while (true)" before.
Consider the new pattern and utility method:
int tokenProgress = -1;
while(IsMakingProgress(ref tokenProgress))
{
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.
will do. thanks!
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 Thanks
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.
Looks great!
Gotcha. No worries then. I'll just tag you in the future. |
Please don't merge. I'd lke to make th change @jcouv suggested. |
@CyrusNajmabadi Can you please retarget to |
(I can't do it myself because your branch includes things not in |
yup. will do. |
e5bb332
to
48b5489
Compare
Provide helper for common pattern. Update test.
48b5489
to
44e0387
Compare
be16a5c
to
da6fa53
Compare
Ok. Ready for final review/merge @jcouv |
Thanks! |
Tagging @jaredpar FYI |
@CyrusNajmabadi Thank you so much! You are a real... llama? |
Fixes #24701