Consider following code:
public class DecimalWrapper
{
public static implicit operator DecimalWrapper(decimal x) => new();
}
[Fact]
public void Test()
{
// Why this even compiles? Since there is no implicit conversion from decimal? -> decimal
DecimalWrapper c = (decimal?)null; // variable 'c' is null!
}
I would not expect it to compile at all, since there is no implicit conversion from decimal? to decimal.
I consider it a bug or do I get something wrong?
I have seen this: Serious bugs with lifted/nullable conversions from int, allowing conversion from decimal
but this looks different and it is old (7+ years), so the bugs should be fixed by now, but cannot be sure since all the links to bug reports are gone)... :(
I would really like to use such code in real solution (tracking of calculations), but this prevents me from it.
PS: I am compiling on Windows.