dotnet / dotnet/fsharp

System.InvalidOperationException - Could not bind function *** in type

Open
#11,533 2 comments 0 reactions 0 assignees View on GitHub
Area-Quotations Bug Impact-Low
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

Following up from the [SO question](https://stackoverflow.com/questions/67389799/why-does-this-f-quotation-fail-at-run-time) it seems there is inconsistent behavior with a specific combination of computation expressions, quotations, generics and extension methods.

I reduced the bug to following scenario:

```
type W<'T,'U> = W of 'T

[]
module M1 =
type WrapBuilder() = class end

let wrap = WrapBuilder()

[]
module M2 =
type WrapBuilder with
member __.Source(s: #seq<_>) = s
member __.Source w : W<_,_> = w

let q = <@@ wrap.Source (W true) @@> // FAILS
```

**Known workarounds**

Any of the following solves the problem:

- Move the builder members into a single module.
- Give W a stronger type
- Evaluate the expression outside of quotations
- Remove the overloaded member __.Source (_:#seq<_>)
- Replace #seq<_> with #seq
- Replace #seq<_> with seq<_>

**Related information**

Ran on dotnet core FSI

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.