Skip to content

Parenthesized/double unit literal ()(()) required in certain scenarios #16254

@brianrourkeboll

Description

@brianrourkeboll

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

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:

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

but not ():

let _ = { new C<unit> 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:

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

as is

type C<'T> = abstract M : 'T -> 'T -> unit
let c = { new C<unit> 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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Diagnosticsmistakes and possible improvements to diagnosticsBugImpact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions