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: unhelpful error message if type assertion has mismatching pointer/non-pointer type #43673

Open
mprobst opened this issue Jan 13, 2021 · 0 comments
Milestone

Comments

@mprobst
Copy link

@mprobst mprobst commented Jan 13, 2021

What version of Go are you using (go version)?

$ go version
go1.15.6

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

n/a

What did you do?

This code:

type FooError interface {
  Something() int
  Error() string
}

err := someCall();
err.(*FooError)

Complains:

impossible type assertion:
	*FooError does not implement error (missing Error method)

The issue is that you need to write err.(FooError).

What did you expect to see?

It'd be much more helpful if it'd call out that FooError does implement error, so the problem is the added pointer indirection.

This mistake is likely because usually the concrete struct types implement error via the pointer reference, so if you change code from the concrete struct error to an interface type, you're likely to miss a * in there.

What did you see instead?

The error message above.

@ianlancetaylor ianlancetaylor changed the title Unhelpful error message if type assertion has mismatching pointer/non-pointer type cmd/compile: unhelpful error message if type assertion has mismatching pointer/non-pointer type Jan 13, 2021
@ianlancetaylor ianlancetaylor added this to the Backlog milestone Jan 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.