dotnet / dotnet/fsharp

Parenthesized/double unit literal `()` → `(())` required in certain scenarios

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

Description

A parenthesized unit literal `()` → `(())` is required as an argument pattern when overriding/implementing a generic method where `unit` is the generic type argument.

**Repro steps**

Provide the steps required to reproduce the problem:

1. Define an abstract method whose single argument is a generic type (`abstract M : 'T -> …`).
2. When implementing or overriding the method when the generic type parameter is `unit`, the argument pattern must be `(())`; using only `()` yields `error FS0768: The member 'M' does not accept the correct number of arguments. 1 argument(s) are expected, but 0 were given`.

#### Single `()` usually means `unit`

```fsharp
type C = abstract M : unit -> unit
let _ = { new C with override _.M () = () }
```

#### Double `(())` is required when overriding/implementing a generic method where `unit` is the generic type argument

Double `(())` compiles:

```fsharp
type C<'T> = abstract M : 'T -> unit
let _ = { new C with override _.M (()) = () }
```

but not `()`:

```fsi
let _ = { new C with override _.M () = () }
------------------------------------^^^^^^

stdin(3,37): error FS0768: The member 'M' does not accept the correct number of arguments. 1 argument(s) are expected, but 0 were given. The required signature is 'C.M: 'T -> unit'.
```

even though this is fine:

```fsharp
type C<'T> = abstract M : 'T * 'T -> unit
let c = { new C with override _.M ((), ()) = () }
```

as is

```fsharp
type C<'T> = abstract M : 'T -> 'T -> unit
let c = { new C with override _.M () () = () }
```

**Expected behavior**

`()` should mean `unit` everywhere.

**Actual behavior**

`(())` is required to represent `unit` in certain scenarios.

**Known workarounds**

N/A.

**Related information**

.NET SDK 8.0.100-rc.2.23502.2 (and probably going far back—I remember running into this in years past).

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.