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

No nullability warnings in best type and type inference #32947

Merged
merged 6 commits into from Feb 1, 2019

Conversation

Projects
None yet
3 participants
@jcouv
Copy link
Member

jcouv commented Jan 30, 2019

The invariant merge rules no longer produce a warning when there is a mismatch.
So scenarios like new[] { x, y } and M(x, y) should not report any diagnostics for failing to find a best type including nullability. Instead, we find a best type, and then produce conversion warnings from the elements to the inferred type.
Then elements can be suppressed.
This also affects the conditional operator.

This allows removing much machinery for passing hadNullabilityMismatch around, and a few "no best type" error codes.

Fixes #30376 (suppression in array initializer and conditional)
Fixes #30151 (suppression in array initializer)
Fixes #30480 (no nullability warning for type inference with lambda argument)

I'll push an additional commit shortly which:
Closes #30955
Closes #30925
Closes #31958
Closes #30941
Closes #28377
Closes #31295
Closes #26654
(Note: I verified that those issues aren't referenced elsewhere in the code)

@jcouv jcouv added this to the 16.0.P4 milestone Jan 30, 2019

@jcouv jcouv self-assigned this Jan 30, 2019

@jcouv jcouv requested a review from dotnet/roslyn-compiler as a code owner Jan 30, 2019

@jcouv jcouv force-pushed the jcouv:suppress-array branch from 9179bb5 to 1f021f5 Jan 30, 2019

@jcouv

This comment has been minimized.

Copy link
Member Author

jcouv commented Jan 30, 2019

@gafter @dotnet/roslyn-compiler for review. Details up top. Thanks

@jcouv jcouv requested a review from dotnet/roslyn-infrastructure as a code owner Jan 30, 2019

@jaredpar
Copy link
Member

jaredpar left a comment

:shipit:

The top-level nullability is the most relaxed of the elements, where `!` is a `~` is a `?`.
The nested nullability is the merged nullability of the best common type. If there is a merge conflict,
the nested nullability is `~` and a warning is reported.
The calculation of the _best type_ element nullability uses the Conversions rules above and the contravariant merging rules.

This comment has been minimized.

@cston

cston Feb 1, 2019

Member

contravariant [](start = 96, length = 13)

"covariant"?

}
}
}

private void ReportNullabilityMismtachInAssignment(SyntaxNode syntaxNode, object sourceType, object destinationType)

This comment has been minimized.

@cston

cston Feb 1, 2019

Member

Mismtach [](start = 38, length = 8)

Typo.

@cston

This comment has been minimized.

Copy link
Member

cston commented Feb 1, 2019

    public void SuppressNullableWarning_Conditional2()

Why rename? The operations are null-coalescing.


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs:36500 in 284d282. [](commit_id = 284d282, deletion_comment = False)

@cston

cston approved these changes Feb 1, 2019

Copy link
Member

cston left a comment

Minor comments only.

@jcouv

This comment has been minimized.

Copy link
Member Author

jcouv commented Feb 1, 2019

Why rename?
Was a mistake. Added a test with a conflicting name, then renamed the wrong one. Thanks

@jcouv jcouv merged commit c8e0e7f into dotnet:master Feb 1, 2019

1 check passed

license/cla All CLA requirements met.
Details

@jcouv jcouv deleted the jcouv:suppress-array branch Feb 1, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment