-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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 warning reported for assignment or explicit cast of possibly null value of unconstrained type parameter type #46044
Comments
Closing as by design. Changing this now would be a breaking change. |
Re-opening following LDM 7/27/2020 (let's re-introduce this warning behind a warning wave, using a distinct diagnostic ID). |
Do we aspire to get this warning into .NET 5? |
@RikkiGibson Yes, although it's probably not a blocker (we could do it in a following warning wave) |
From offline discussion, if possible we should use the existing warning, CS8600, and report warnings for these cases when using |
If/when we decide to move ahead with investigation (what's the impact on roslyn/VS/runtime), we should remember to let LDM know. |
No warnings are reported for the assignment to
t
inF1()
or the explicit cast(T)
inF2()
.For type parameters with constraints (or explicit types), the compiler reports
warning CS8600: Converting null literal or possible null value to non-nullable type
for those cases. The warning is not a safety warning because the compiler still tracks the "maybe default" state of the value and reports actual safety warnings when the values are used, as in the warnings reported forreturn t;
above. But it is a difference in behavior between unconstrained type parameters and other types.The reason the compiler does not report warnings for unconstrained type parameters is because in C#8 there is no syntax to specify the nullable version of the type parameter so any warning would require a
!
suppression.Post C#8, unconstrained type parameters can be annotated, so the code above could be replaced with the following. Given that, should the compiler report
CS8600
for the cases above?The text was updated successfully, but these errors were encountered: