Skip to content

Error for extra implicit conversion is needed #12994

@Lanayx

Description

@Lanayx

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Compiler-CheckingType checking, attributes and all aspects of logic checkingBugImpact-High(Internal MS Team use only) Describes an issue with extreme impact on existing code.

    Type

    No type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions