-
Notifications
You must be signed in to change notification settings - Fork 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
ref ternary operator nullability suppressions #8379
Comments
My opinion is in comments:
My thinking here is, (leaving aside the inner workings of Roslyn) the type of the ternary as a whole is determined depending on its branches, then analysis continues onward. |
Discussed at LDM 2024-08-29. Going with option 1. |
How should suppressions in ref ternaries behave? Currently in Roslyn they don't work - all of these are warnings:
Conditional operator spec
Suppressing the whole ternary should continue to do nothing. The spec says: "type of the result can be either type." I.e., the outer suppression works with the already-chosen type (
ref object
orref object?
) and all it can do is suppress any "assignment mismatch" warning, not the inner "operands mismatched" warning.Which branch should a suppression work on? And where the warning should be reported?
Reusing "best common type" and type inference.
BindRefConditionalOperator
) relies on type inference. On the other hand, nullability analysis (NullableWalker
) uses type inference only for non-ref ternaries.Type inference picks one of the arguments/types as the winner and warns on the other.:
Ref ternaries could behave similarly - reporting the warning on just one operand and allowing suppression only on that one, as well.
Keep what the spec says - i.e., there can be only an identity conversion between the operands.
ref object
andref object?
and we consider nullability, they are not convertible to each other via an identity conversion.The text was updated successfully, but these errors were encountered: