dotnet / fsharp

The F# compiler, F# core library, F# language service, and F# tooling integration for Visual Studio
https://dotnet.microsoft.com/languages/fsharp
MIT License
3.91k stars 785 forks source link

Internal error of single case active pattern within `let` binding #16856

Open ijklam opened 8 months ago

ijklam commented 8 months ago

图片

Repro steps

Input following code into fsi:

let (|T|) (f: _ -> _) = ();;
match id with T -> ();;
let (T) = id;;

Expected behavior

Both works.

Actual behavior

let way doesn't work.

Known workarounds

Use match.

Related information

Provide any related information (optional):

edgarfgp commented 7 months ago

Looking into this. I think this should not throw an internal error. Found a workaround to make this compile adding unit -> unit

let (|T|) (f: _ -> _) = ()
match id with T -> ()
let (T: unit -> unit) = id

Edit: this will also avoid the internal error

let (|T|) (f: unit -> unit) = f()
match id with T -> ()
let (T) = id

let (|T|) f = f()
match id with T c -> c
let (T) = id

cc @vzarytovskii