dotnet / dotnet/fsharp

Oddities in statically resolved method constraints and method overloading

Open
#3,814 13 comments 0 reactions 0 assignees View on GitHub
Area-Compiler-SRTP Bug Impact-Medium
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

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 a

printfn "%d" (Test2 0)
```
I expected return 2, but actually it return 1

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.