Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better diagnostic message for FS0856 #15307

Closed
Szer opened this issue Jun 4, 2023 · 0 comments · Fixed by #15308
Closed

Better diagnostic message for FS0856 #15307

Szer opened this issue Jun 4, 2023 · 0 comments · Fixed by #15308
Labels
Area-Diagnostics mistakes and possible improvements to diagnostics
Milestone

Comments

@Szer
Copy link
Contributor

Szer commented Jun 4, 2023

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.

@github-actions github-actions bot added this to the Backlog milestone Jun 4, 2023
@0101 0101 added Area-Diagnostics mistakes and possible improvements to diagnostics and removed Needs-Triage labels Jun 12, 2023
T-Gro pushed a commit that referenced this issue Jun 23, 2023
…nts (#15308)

* Introduces better diagnostic for overriding members with tuple arguments
#15307
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Diagnostics mistakes and possible improvements to diagnostics
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants