Skip to content
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

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

Merged
merged 2 commits into from
Jul 23, 2021

Conversation

cston
Copy link
Member

@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.

@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
Member 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
Copy link
Member 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
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
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
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