Error for extra implicit conversion is needed
Right now implicit type conversion happens only one-step (like int-> float or float -> Nullable<float>), but when we try to do two-step conversion (e.g. int -> Nullable<float>) there is no warning on compile time and we've exception in runtime.
Repro steps
type C() =
member val X = System.Nullable(1.0) with get, set
C(X = 1)
Expected behavior
The code either works or gives compiler warning
Actual behavior
The code compiles successfully but in runtime the exception is raised
Unhandled exception. System.InvalidCastException: Unable to cast object of type 'System.Int32' to type 'System.Nullable`1[System.Double]'.
Known workarounds
Fix the code (e.g. write C(X = 1.0)) after facing the error in the runtime
Related information
dotnet 6.0.201 fsharp 6.0.3
The same as or related to https://github.com/dotnet/fsharp/issues/12414.
@kerams probably not the same, since the fix was merged long time ago
Yes I can't see a duplicate of this bug - the corresponding code with named argument works, so it's specific to setter-properties
type C(x: System.Nullable<int>) =
member val Y = System.Nullable(1.0) with get, set
C(x = 1)
Specifically this pattern https://github.com/dotnet/fsharp/issues/12994#issuecomment-1103390228 bit us today again, given the compiler is effectively outputting invalid IL could this version of the bug also be fixed for 7.0?
@vzarytovskii
I might be able to help here with some guidance, the previous PR fixing the first kind should already help a lot but I probably need a few pointers to where the constructor logic lives.
I guess @dsyme can give you pointers quicker than me. I will look at it otherwise.