Skip to content

Oddities in statically resolved method constraints and method overloading  #3814

@RealmPlume

Description

@RealmPlume

Case 1

type Test() =
     member __.Equals (_: Test) = true

let inline Equals(a: obj) (b: ^t) =
    match a with
    | :? ^t as x -> (^t: (member Equals: ^t -> bool) (b, x))
    | _-> false

let a: Test = Test()
let b:Test = Test()
//b <- null

printfn "%A" (Equals a b)

I expected to call Test.Equals: Test->unit, (Equals a b) return true
but actually it call Object.Equals: obj->unit, return false

Case 2:

type X =
    static member Method (a: obj) = 1
    static member Method (a: int) = 2
    static member Method (a: int64) = 3


let inline Test< ^t, ^a when ^t: (static member Method: ^a -> int)> (value: ^a) =
    ( ^t: (static member Method: ^a -> int)(value))

let inline Test2< ^t> a = Test<X, ^t> a

printfn "%d" (Test2<int> 0)

I expected return 2, but actually it return 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Compiler-SRTPbugs in SRTP inference, resolution, witness passing, code genBugImpact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.

    Type

    Projects

    Status

    In Progress

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions