Avoid crash with 'new ref[]'#25505
Conversation
There was a problem hiding this comment.
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
There was a problem hiding this comment.
See how pointers are handled, the same approach might work here.
In reply to: 175167784 [](ancestors = 175167784)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
TestNewRefArray [](start = 20, length = 15)
We should test SemanticModel and IOperation, including scenarios when there is an object initializer and a collection initializer. #Closed
|
Done with review pass (iteration 1) #Closed |
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) |
|
@AlekseyTs Please take another look when you get the chance. The binding now keeps children bound nodes in error case. Thanks |
|
@dotnet/roslyn-compiler for a second review. Thanks |
| @@ -1575,6 +1575,7 @@ internal enum ErrorCode | |||
| WRN_TupleBinopLiteralNameMismatch = 8383, | |||
| ERR_TupleSizesMismatchForBinOps = 8384, | |||
| ERR_ExprCannotBeFixed = 9385, | |||
There was a problem hiding this comment.
9385, [](start = 32, length = 5)
Not your PR but this looks wrong.
There was a problem hiding this comment.
There was a problem hiding this comment.
I'll go ahead and fix in this PR.
In reply to: 177497759 [](ancestors = 177497759,177497404,177497359)
| @@ -1575,6 +1575,7 @@ internal enum ErrorCode | |||
| WRN_TupleBinopLiteralNameMismatch = 8383, | |||
| ERR_TupleSizesMismatchForBinOps = 8384, | |||
| ERR_ExprCannotBeFixed = 9385, | |||
|
approved |
| WRN_TupleBinopLiteralNameMismatch = 8383, | ||
| ERR_TupleSizesMismatchForBinOps = 8384, | ||
| ERR_ExprCannotBeFixed = 9385, | ||
| ERR_ExprCannotBeFixed = 8385, |
There was a problem hiding this comment.
Are there no references to CS9385 in tests?
There was a problem hiding this comment.
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).
|
test windows_debug_unit32_prtest please |
|
test windows_debug_unit64_prtest please |
|
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. |
…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
new ref[]is parsed as an object creation where the type is aRefTypeSyntaxwhose 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.