-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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. |
||
IArrayCreationOperation (OperationKind.ArrayCreation, Type: ?[], IsInvalid) (Syntax: 'new[2]/*</bind>*/') | ||
Dimension Sizes(1): | ||
ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 1, IsInvalid, IsImplicit) (Syntax: 'new[2]/*</bind>*/') | ||
ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 0, IsInvalid, IsImplicit) (Syntax: 'new[2]/*</bind>*/') | ||
Initializer: | ||
IArrayInitializerOperation (1 elements) (OperationKind.ArrayInitializer, Type: null, IsInvalid) (Syntax: '2]/*</bind>*/') | ||
Element Values(1): | ||
ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 2, IsInvalid) (Syntax: '2') | ||
IArrayInitializerOperation (0 elements) (OperationKind.ArrayInitializer, Type: null, IsInvalid) (Syntax: '') | ||
Element Values(0) | ||
"; | ||
var expectedDiagnostics = new DiagnosticDescription[] { | ||
// CS1003: Syntax error, ']' expected | ||
// file.cs(6,31): error CS0178: Invalid rank specifier: expected ',' or ']' | ||
// var x = /*<bind>*/new[2]/*</bind>*/; | ||
Diagnostic(ErrorCode.ERR_SyntaxError, "2").WithArguments("]", "").WithLocation(6, 31), | ||
// CS1514: { expected | ||
Diagnostic(ErrorCode.ERR_InvalidArray, "2").WithLocation(6, 31), | ||
// file.cs(6,44): error CS1514: { expected | ||
// var x = /*<bind>*/new[2]/*</bind>*/; | ||
Diagnostic(ErrorCode.ERR_LbraceExpected, "2").WithLocation(6, 31), | ||
// CS1003: Syntax error, ',' expected | ||
Diagnostic(ErrorCode.ERR_LbraceExpected, ";").WithLocation(6, 44), | ||
// file.cs(6,44): error CS1513: } expected | ||
// var x = /*<bind>*/new[2]/*</bind>*/; | ||
Diagnostic(ErrorCode.ERR_SyntaxError, "]").WithArguments(",", "]").WithLocation(6, 32), | ||
// CS1513: } expected | ||
Diagnostic(ErrorCode.ERR_RbraceExpected, ";").WithLocation(6, 44), | ||
// file.cs(6,27): error CS0826: No best type found for implicitly-typed array | ||
// var x = /*<bind>*/new[2]/*</bind>*/; | ||
Diagnostic(ErrorCode.ERR_RbraceExpected, ";").WithLocation(6, 44) | ||
Diagnostic(ErrorCode.ERR_ImplicitlyTypedArrayNoBestType, "new[2]/*</bind>*/").WithLocation(6, 27) | ||
}; | ||
|
||
VerifyOperationTreeAndDiagnosticsForTest<ImplicitArrayCreationExpressionSyntax>(source, expectedOperationTree, expectedDiagnostics); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.