Skip to content

Statically resolved type parameters don't propagate correctly, and hashed typenames like ^?9104 in unjust compile error #3508

@abelbraaksma

Description

@abelbraaksma

I must admit, I have seen this error before, but I have always managed to somehow mysteriously fix it, but now I'm stymied and I decided to report it.

The issue is: compile errors are raised on missing type parameters, but the error shows a garbled name which makes it virtually impossible to understand what is going on.

In addition, in this particular scenario, the error is incorrect, I think this source code should compile.

Repro steps

To repro, just copy the following code and try to compile, the error is on the last line.

type MyByte = MyByte of byte with
    static member MinValue = MyByte Byte.MinValue
    static member MaxValue = MyByte Byte.MaxValue
    static member op_Explicit (MyByte x): int64 = int64 x
    static member op_Explicit (MyByte x): double = double x

let inline isWithinMinMaxRange< ^b, ^a when 
                    ^b: comparison 
                    and ^a: comparison 
                    and ^b: (static member MinValue: ^b) 
                    and ^b: (static member MaxValue: ^b)
                    and ^b : (static member op_Explicit: ^b -> ^a) > 
                    (value: ^a) =

    let minRange = ((^b) : (static member MinValue: ^b) ())
    let maxRange = ((^b) : (static member MaxValue: ^b) ())
    let cast v = (^b : (static member op_Explicit: ^b -> ^a) v)

    value > cast minRange && value < cast maxRange

// compiles and runs fine, returns false
let test() = 
    isWithinMinMaxRange<MyByte, _> 256.0 
    
// Does not compile, FS0001 and FS0043 on the last line
let test<  ^source, ^value when 
        ^source: comparison 
        and ^value: comparison 
        and ^source: (static member MinValue: ^source) 
        and ^source: (static member MaxValue: ^source)
        and ^source : (static member op_Explicit: ^source -> ^value)> (v: ^value) =
    isWithinMinMaxRange< ^source, ^value> v     // error FS0001/FS0043: A type parameter is missing a constraint 'when  ^source : (static member op_Explicit :  ^source ->  ^?9104)'

Expected behavior

This should either compile just fine, or give an error that shows specifically what type parameter constraint is missing. The hashed names should not be shown. However, in this case, I don't think there's a constraint missing, as the call-site has equal type parameter constraints as the definition.

Actual behavior

It throws both FS0001 and FS0043, with equal texts:

error FS0001: A type parameter is missing a constraint 'when ^source : (static member op_Explicit : ^source -> ^?9104)'

and
error FS0043: A type parameter is missing a constraint 'when ^source : (static member op_Explicit : ^source -> ^?9104)'

Known workarounds

None, unfortunately (except for dynamic type resolution, but that is not an option here).

Related information

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugImpact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions