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

Nullable array types are accepted in declaration patterns #31991

Closed
alrz opened this issue Dec 21, 2018 · 5 comments
Closed

Nullable array types are accepted in declaration patterns #31991

alrz opened this issue Dec 21, 2018 · 5 comments
Assignees
Milestone

Comments

@alrz
Copy link
Member

alrz commented Dec 21, 2018

Version Used: NullableReferenceTypes (2f8fefa)

Steps to Reproduce:

    public void M(object o) {
        _ = o is string[]?;
        _ = o is string?;
        _ = o is string[]? a; // no error (incorrect)
        _ = o is string? b; // error
    }

Expected Behavior:

Error on third line as well. Patterns don't support nullable types.

Plus, I don't know why the first two are decided to be valid.

Actual Behavior:

Errors only on non-array nullables in patterns.

@alrz
Copy link
Member Author

alrz commented Dec 21, 2018

Also I think there's room for diagnostic clarity instead of giving syntax errors.

@jcouv
Copy link
Member

jcouv commented Dec 21, 2018

FYI @gafter

@gafter gafter added this to the 16.0.P2 milestone Dec 22, 2018
@gafter gafter self-assigned this Dec 22, 2018
@jaredpar jaredpar added the Bug label Jan 2, 2019
@gafter
Copy link
Member

gafter commented Jan 3, 2019

if (o is A[]   ? b
                   : c)  // OK, this means `(o is A[]) ? b : c` because nullable types are not permitted for a pattern's type

if (o is A[]   ? b
                   && c) // error: 'cannot use nullable reference type for a pattern' or 'expected :'

if (o is A[][] ? b
                   : c)  // OK, this means `(o is A[][]) ? b : c`

if (o is A[][] ? b
                   && c) // OK, this means `(o is A[][]? b) && c` because `A[][]?` is not a nullable type

@alrz
Copy link
Member Author

alrz commented Jan 4, 2019

Another case where this is incorrectly accepted:

#nullable enable
public class C {
    public void M() {
    	_ = new C?(); // error 
        _ = new string[50]?; // no error (incorrect)
        _ = new string[50]?[,]; // no error (incorrect)
    }
}

Looks like the same issue.

@gafter
Copy link
Member

gafter commented Jan 18, 2019

Fixed in #32432

@gafter gafter closed this as completed Jan 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants