Skip to content

cmd/compile: impossible type assertion reports wrong signature for methods that don't match in case #50816

@dominikh

Description

@dominikh

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

$ go version
go version devel go1.18-6eb58cdffa Tue Jan 25 22:56:45 2022 +0000 linux/amd64

Does this issue reproduce with the latest release?

No.

What did you do?

https://go.dev/play/p/M_0U_6fSpFp

What did you expect to see?

./foo.go:17:7: impossible type assertion:
	T1 does not implement I (missing Foo method)
		have foo()
		want Foo()
./foo.go:18:7: impossible type assertion:
	T2 does not implement I (missing Foo method)
		have foo() string
		want Foo()

What did you see instead?

./foo.go:17:7: impossible type assertion: i.(T1)
	T1 does not implement I (missing Foo method)
		have foo() at ./foo.go:9:11
		want Foo()
./foo.go:18:7: impossible type assertion: i.(T2)
	T2 does not implement I (wrong type for Foo method)
		have foo() string at ./foo.go:13:11
		want Foo()

The compiler complains about the wrong signature even though the method names don't match, which I think is the more important error to report. Bisects to 429d1e0.

/cc @danscales

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions