Implicit conversion to System.Double with a nullable struct via compiler generated locals: why is this failing?

前端 未结 2 738
时光说笑
时光说笑 2021-01-31 03:49

Given the following, why does the InvalidCastException get thrown? I can\'t see why it should be outside of a bug (this is in x86; x64 crashes with a 0xC0000005 in clrjit.dll).<

2条回答
  •  醉梦人生
    2021-01-31 04:38

    This sure looks like a compiler bug to me. The IL suggests the compiler is generating code to convert the MyDouble? to a double with the conversion operator, then to a double?. But takes a nosedive when it then uses the conversion operator again on that double?. That's bad, wrong argument type. Nor is there a need.

    This feedback article resembles this bug. Over 6 years old already, that must be a tricky part of the compiler. I do imagine it is.

提交回复
热议问题