Skip to content

cmd/compile: unhelpful error message if type assertion has mismatching pointer/non-pointer type #43673

Open
@mprobst

Description

@mprobst

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsFixThe path to resolution is known, but the work has not been done.compiler/runtimeIssues related to the Go compiler and/or runtime.help wanted

    Type

    No type

    Projects

    Status

    Triage Backlog

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions