dotnet / dotnet/fsharp

Internal error: Undefined or unsolved type variable with SRTP chains

Open
#5,973 7 comments 0 reactions 0 assignees View on GitHub
Area-Compiler-SRTP Bug Impact-Low
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 22h
Merged PRs (30d)
144

Description

While digging into #4924 I found an example with SRTP chains which produces an internal error.

#### Repro steps
Try compiling this in FSI:
```fsharp
type Bar =
static member inline bar (f: ^c -> ^b, (a, b) : ^c) : ^b = f (a, b)
static member inline bar (f: ^c -> ^b, (a, b, c) : ^c) : ^b = f (a, b, c)

let inline bar_(f:^a -> ^b) (x: ^c) : ^d when (^bar or ^d) : (static member bar : (^a -> ^b) * ^c -> ^d) =
((^bar or ^d) : (static member bar : (^a -> ^b) * ^c -> ^d)(f, x))

type Foo =
static member inline foo (f : ^a -> ^b, (a, b)) : ^c = bar_ f (a,b)
static member inline foo (f : ^a -> ^b, (a, b, c)) : ^c = bar_ f (a,b,c)

let inline foo< ^foo, ^a, ^b, ^c, ^d when (^foo or ^a) : (static member foo : (^a -> ^b) * ^c -> ^d)> (f: ^a -> ^b) (x: ^c) : ^d =
((^foo or ^a) : (static member foo : (^a -> ^b) * ^c -> ^d)(f, x))

let inline callFoo (f: ^a -> ^b) (x: ^c) : ^d when (Foo or ^d) : (static member foo: (^a -> ^b) * ^c -> ^d)=
foo f x

let test = (fun (a : int, b : int) -> (a, b))

let appliedFoo : int * int -> int * int =
callFoo test
```

Will produce an error like: `FS0073: Internal Error: Undefined or unsolved type variable: ^_?35727`
for the last function `appliedFoo`.
#### Expected behavior

No internal error.

#### Actual behavior

An internal error is thrown.

#### Known workarounds

None

#### Related information

F# 4.5

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.