Skip to content

Better diagnostic message for FS0856 #15307

@Szer

Description

@Szer

Repro

type IFoo = 
  abstract member Bar: (int * int) -> int
  
type Foo =
  interface IFoo with
    member _.Bar (x, y) = x + y

Current behavior:

error FS0856: This override takes a different number of arguments to the corresponding abstract member. The following abstract members were found:
   abstract IFoo.Bar: (int * int) -> int

Problem

Interface declares incoming argument as a tuple (a lot of times by mistake, alas)
But Implementation defines two separate arguments, so we got an error.

And this error is a noob trap. A lot of questions "why such code doesn't work?"
Fix is simple

  • either add additional layer of parentheses
member _.Bar ((x, y)) = x + y
  • or remove parentheses from interface declaration
abstract member Bar: int * int -> int

I think compiler correctly throws an error here, but message of that error could be different to help people out of this mess.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Diagnosticsmistakes and possible improvements to diagnostics

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions