Skip to content

Avoid crash with 'new ref[]'#25505

Merged
jcouv merged 5 commits intodotnet:dev15.7.xfrom
jcouv:ref-crash
Mar 27, 2018
Merged

Avoid crash with 'new ref[]'#25505
jcouv merged 5 commits intodotnet:dev15.7.xfrom
jcouv:ref-crash

Conversation

@jcouv
Copy link
Copy Markdown
Member

@jcouv jcouv commented Mar 15, 2018

new ref[] is parsed as an object creation where the type is a RefTypeSyntax whose type is ?[] (an array with missing type).
From discussion with @VSadov, trying to fix this in the parser would introduce context, so a binding fix is preferable, even if the parsing diagnostic isn't good.

Customer scenario

Type new ref[] to crash the compiler and VS.

Bugs this fixes

Fixes #25264

Risk

Performance impact

Is this a regression from a previous update?

No

Root cause analysis

How did we miss it? What tests are we adding to guard against it in the future?

How was the bug found?

Reported by customer.

@jcouv jcouv added this to the 15.7 milestone Mar 15, 2018
@jcouv jcouv self-assigned this Mar 15, 2018
@jcouv jcouv requested a review from a team as a code owner March 15, 2018 21:13
Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs Mar 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return BadExpression(node, LookupResultKind.NotCreatable); [](start = 20, length = 58)

Instead of bailing out like that, we should continue binding for SemanticModel and IOperation benefits. For example, we might go into BindClassCreationExpression (because an array is a class) and handle the array type there specially, if that is even required (we might just get an acceptable error about missing constructor, etc.) #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See how pointers are handled, the same approach might work here.


In reply to: 175167784 [](ancestors = 175167784)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BindClassCreationExpression ends up returning a bad expression anyways (line 4683) :-(
I can do the change here, but it's not going to help with semantic model or IOperation.
If we want to eliminate BadExpression, it's probably best to do as a separate effort.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BindClassCreationExpression ends up returning a bad expression anyways (line 4683) :-(

The goal is not to avoid producing bad expression, the goal is to not drop constituent pieces and it looks like the bad expression produced at line 4683 doesn't drop them. So they will be available to SemanticModel and IOperation. Tests should confirm that


In reply to: 175974841 [](ancestors = 175974841)

Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs Mar 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestNewRefArray [](start = 20, length = 15)

We should test SemanticModel and IOperation, including scenarios when there is an object initializer and a collection initializer. #Closed

@AlekseyTs
Copy link
Copy Markdown
Contributor

AlekseyTs commented Mar 16, 2018

Done with review pass (iteration 1) #Closed

@AlekseyTs
Copy link
Copy Markdown
Contributor

AlekseyTs commented Mar 16, 2018

                return BadExpression(node, LookupResultKind.NotCreatable);

While we are here, we might want to fix this place too. #Closed


Refers to: src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs:3577 in d5dac0b. [](commit_id = d5dac0b55b5e61692c08c32c0e2dbf9fdb4ca435, deletion_comment = False)

@jcouv jcouv added PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. and removed PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. labels Mar 16, 2018
@jcouv
Copy link
Copy Markdown
Member Author

jcouv commented Mar 23, 2018

@AlekseyTs Please take another look when you get the chance. The binding now keeps children bound nodes in error case. Thanks

Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (iteration 3)

@jcouv
Copy link
Copy Markdown
Member Author

jcouv commented Mar 27, 2018

@dotnet/roslyn-compiler for a second review. Thanks
Note: I rebased the changes and resolved conflicts (error code and resx file) after Aleksey's review.

@@ -1575,6 +1575,7 @@ internal enum ErrorCode
WRN_TupleBinopLiteralNameMismatch = 8383,
ERR_TupleSizesMismatchForBinOps = 8384,
ERR_ExprCannotBeFixed = 9385,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

9385, [](start = 32, length = 5)

Not your PR but this looks wrong.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will file a bug.


In reply to: 177497359 [](ancestors = 177497359)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#25752


In reply to: 177497404 [](ancestors = 177497404,177497359)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll go ahead and fix in this PR.


In reply to: 177497759 [](ancestors = 177497759,177497404,177497359)

Copy link
Copy Markdown
Member

@jaredpar jaredpar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@@ -1575,6 +1575,7 @@ internal enum ErrorCode
WRN_TupleBinopLiteralNameMismatch = 8383,
ERR_TupleSizesMismatchForBinOps = 8384,
ERR_ExprCannotBeFixed = 9385,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be 8385?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good eye. Fixed

@jaredpar
Copy link
Copy Markdown
Member

approved

WRN_TupleBinopLiteralNameMismatch = 8383,
ERR_TupleSizesMismatchForBinOps = 8384,
ERR_ExprCannotBeFixed = 9385,
ERR_ExprCannotBeFixed = 8385,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there no references to CS9385 in tests?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't typically update all the textual references in VerifyDiagnostics (the comments). Only the error enum entry is really checked (for C# at least).

@jcouv
Copy link
Copy Markdown
Member Author

jcouv commented Mar 27, 2018

test windows_debug_unit32_prtest please

@jcouv
Copy link
Copy Markdown
Member Author

jcouv commented Mar 27, 2018

test windows_debug_unit64_prtest please

@alrz
Copy link
Copy Markdown
Member

alrz commented Mar 27, 2018

PDBUsingTests doesn't seem to be flaky. probably the baseline need to be updated. I see those failures in all of my recent PRs targeting dev15.7.x.

@jcouv
Copy link
Copy Markdown
Member Author

jcouv commented Mar 27, 2018

@alrz See discussion in #25753

@jcouv jcouv merged commit f697953 into dotnet:dev15.7.x Mar 27, 2018
@jcouv jcouv deleted the ref-crash branch March 27, 2018 19:22
333fred added a commit to 333fred/roslyn that referenced this pull request Mar 28, 2018
…features/dataflow

* dotnet/dev15.7.x:
  Fix inference when tuple names differ (dotnet#25738)
  Avoid crash with 'new ref[]' (dotnet#25505)
  Skip some PDBUsingTests tests to unblock CI (dotnet#25753)
  Disable Spanish queue
  Tuple equality: Optimize cases where nullable always has value (dotnet#25644)
  Bump prerelease version to beta4
  Fix failure to initialize RemoteWorkspace in the out-of-process host
  remove whitespace
  Removing package dependency for Microsoft.VisualStudio.Text.UI.Wpf in EditorFeatures
  Removing package dependency for Microsoft.VisualStudio.Text.UI.Wpf in CSharpEditorFeatures
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.

5 participants