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

Improve error reporting: override method does not match abstract member #1430

Closed
Tracked by #1103
anton-pt opened this issue Aug 13, 2016 · 3 comments
Closed
Tracked by #1103

Comments

@anton-pt
Copy link

anton-pt commented Aug 13, 2016

What

When overriding an abstract member like this:

type Base() =
    abstract member Member: int * string -> string
    default x.Member (i, s) = s

type Derived1() =
    inherit Base()
    override x.Member() = 5

type Derived2() =
    inherit Base()
    override x.Member (i : int) = "Hello"

type Derived3() =
    inherit Base()
    override x.Member (s : string, i : int) = sprintf "Hello %s" s

FSI yields the error message
error FS0856: This override takes a different number of arguments to the corresponding abstract member
for the definitions in Derived1 and Derived2 and
error FS0001: This expression was expected to have type int but here has type string
for the definition in Derived3.

Why

The error message does not suggest the correct signature of the abstract methods so you don't know if you have them in the right order, etc. This can be quite a pain when inheriting from a class with a lot of members (such as a WPF Window) and trying to find the right overload.

How

In all 3 cases above, the error message should include the full type signature(s) for Member (including any overloads).

Bonus round

It would also be great to provide suggestions for members which can be overridden if the programmer has a typo in the method name, such as:

type Derived4() =
    inherit Base()
    override x.Memer (i, s) = sprintf "Hello %d" i

This currently produces the error:
error FS0855: No abstract or interface member was found that corresponds to this override

@forki
Copy link
Contributor

forki commented Dec 6, 2016

WIP PR at #1950

forki added a commit to forki/visualfsharp that referenced this issue Dec 7, 2016
forki added a commit to forki/visualfsharp that referenced this issue Dec 7, 2016
forki added a commit to forki/visualfsharp that referenced this issue Dec 8, 2016
@isaacabraham
Copy link
Contributor

@forki can this be closed?

@forki
Copy link
Contributor

forki commented Jan 20, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants