dotnet / dotnet/fsharp

When implementing interfaces, cancellable tasks can produce errors in the wrong places

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

Description

**Repro steps**

Consider this code:

```fsharp
type ITest =
abstract member DoStuff: unit -> CancellableTask

type Test() =
interface ITest with
member _.DoStuff() =
cancellableTask {
let _test1 = "blah"

let! _test2 = CancellableTask.getCurrentCancellationToken()

return "blah"
}
```

**Expected behavior**

I would imagine the code producing an error either around the `cancellableTask` definition or around the last line of the CE.
Provide a description of the expected behavior.

**Actual behavior**

Actually the code produces an error at the first bang binding.

![image](https://github.com/dotnet/fsharp/assets/5451366/9033bfcc-659d-4b32-a5bd-da8b6e39e8f0)

**Known workarounds**

None, just figuring out what's going on and fixing the error.

**Related information**

The error span seems reasonable when interfaces are not in the game:

![image](https://github.com/dotnet/fsharp/assets/5451366/ccfdacd7-98ee-4c63-9dde-d85f1e004aa6)

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.