Open jcouv opened 5 years ago
I think I figured out the answer for this inadvertently. May solve at least part of this as part of "improved definite assignment".
I think we should see what happens when we make the analysis a little more strict. RemoveConversion should not unwrap user-defined conversions except in the following scenarios:
null->null
, notnull->notnull
requirements are met)[return: NotNullIfNotNull]
attribute referencing the parameter. This attribute is almost always used on conversions which meet the null->null
, notnull->notnull
requirements. I do not know if we should also require that the parameter and return types of the conversion are nullable.If the impact of this on real-world code seems minimal, then I'd like to try shipping it as a bug fix level change. But if the impact is pretty severe, then we should look at what scenarios we broke, and whether those breaks are indicative of bugs in user code, or of an essentially valid usage pattern that wasn't properly annotated or that we didn't account for.
/cc @jcouv @333fred
Depending on the conversion, we can learn something about
x
when we learn that(C)x
is null. For instance, in an implicit reference conversion.Also, in a scenario with a user-defined conversion
operator C(X x)
with non-null input and output, I think we can infer from the contract thatx
was null if the output was null.