dotnet / dotnet/fsharp

SRTP bug in type inference

Open
#10,519 7 comments 0 reactions 1 assignee Claimed by @dsyme View on GitHub
Area-Compiler-SRTP Bug Impact-Low
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

I think it's serious:
```
type Ah =
static member plus (a: Ah, b: Ah) = "Ah"

type TestPlus =

static member plus(a: int, b: int) = a + b
static member plus(a: string, b: string) = a + b
static member plus (a: 'T, b: 'T) = "TestPlus"

let inline plus'< ^t,^x, ^r when (^t or ^x or ^r):(static member plus: ^x * ^x -> ^r)> a b =
((^t or ^x or ^r):(static member plus: ^x * ^x -> ^r) (a, b))

let inline plus a b = plus' a b

let foo2 (a: int) (b: int) = plus a b
```
the code compile to :
```
public static int foo2(int a) (int b)
{
//IL_0006: Expected I4, but got O
return (int)"TestPlus";
}
```
`foo2 1 2`
result is `-464137512`

the type inference should do something here.

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.