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

cmd/compile: tip regression: "incompatible type" error message should include more info #48483

Closed
rogpeppe opened this issue Sep 20, 2021 · 2 comments

Comments

@rogpeppe
Copy link
Contributor

commit a83a558

When a type isn't compatible with an interface type because it doesn't implement the required methods, the compiler used to mention at least one method that's messing. With the latest tip that's no longer the case - it just says "incompatible type" with no hint as to what's wrong.

For example, with this code:

package main

type I interface {
	Foo()
	Bar()
}

type S struct{}

func (S) Foo() {
}

func main() {
	var _ I = S{}
}

Go 1.17 prints the error:

./tst.go:14:6: cannot use S{} (type S) as type I in assignment:
	S does not implement I (missing Bar method)

but Go tip just prints:

./tst.go:14:12: incompatible type: cannot use S{} (value of type S) as I value

Historically I've found the additional information extremely helpful, so I think it should be reinstated.
Aside: I'd actually go further than that - I've often thought that it would be better if the error
showed all the missing methods, not just some arbitrary method, because that gives a better
idea of what's going on.

@cuonglm
Copy link
Member

cuonglm commented Sep 20, 2021

Seems duplicated of #48471

@rogpeppe
Copy link
Contributor Author

@cuonglm Thanks! I agree that this is a dupe.

@golang golang locked and limited conversation to collaborators Sep 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants