Skip to content

Parse [ after nullable type as part of the type#55044

Merged
cston merged 2 commits intodotnet:release/dev16.11from
cston:55013
Jul 23, 2021
Merged

Parse [ after nullable type as part of the type#55044
cston merged 2 commits intodotnet:release/dev16.11from
cston:55013

Conversation

@cston
Copy link
Copy Markdown
Contributor

@cston cston commented Jul 22, 2021

Parse ? [ as a nullable array type always in switch and is expression pattern types: x switch { string ? [] y => y }

As a result, parentheses are required when the [ starts a lambda expression with attributes: x is string ? ([A] y => y) : z

Fixes #55013.

@ghost ghost added the Area-Compilers label Jul 22, 2021
@cston cston marked this pull request as ready for review July 22, 2021 07:51
@cston cston requested a review from a team as a code owner July 22, 2021 07:51
@cston
Copy link
Copy Markdown
Contributor Author

cston commented Jul 22, 2021

                        return !CanStartExpression();

Before this change, CanStartExpression() returned true for [ in x switch { string?[] y => y } so [] y => y was treated as a lambda expression with attributes rather than a well-formed switch expression arm.


In reply to: 885021921


Refers to: src/Compilers/CSharp/Portable/Parser/LanguageParser.cs:6861 in 4b559f9. [](commit_id = 4b559f9, deletion_comment = False)

@cston cston added this to the 16.11 milestone Jul 22, 2021
@cston
Copy link
Copy Markdown
Contributor Author

cston commented Jul 22, 2021

@dotnet/roslyn-compiler, please review this fix for parsing nullable array types in switch and is patterns. The actual parsing change is small, but there are a number of parsing tests included. Thanks.

[Fact]
public void NullableType_Switch_03()
{
string source = "x switch { string? [A] y => y }";
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.

Makes me glad that we decided to separate list-pattern from the more general recursive pattern ;-)

Copy link
Copy Markdown
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

LGTM Thanks (iteration 2)

@jcouv
Copy link
Copy Markdown
Member

jcouv commented Jul 23, 2021

Approved by BU and Division triage in email. Can be merged to 16.11
FYI @allisonchou

@cston cston merged commit ebbae5b into dotnet:release/dev16.11 Jul 23, 2021
@cston cston deleted the 55013 branch March 15, 2024 18:18
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.

3 participants