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: impossible type assertion reports wrong signature for methods that don't match in case #50816

Closed
dominikh opened this issue Jan 26, 2022 · 2 comments
Labels
NeedsInvestigation
Milestone

Comments

@dominikh
Copy link
Member

@dominikh dominikh commented Jan 26, 2022

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

@ianlancetaylor ianlancetaylor added the NeedsInvestigation label Jan 26, 2022
@ianlancetaylor ianlancetaylor added this to the Go1.18 milestone Jan 26, 2022
@danscales danscales self-assigned this Jan 26, 2022
@danscales
Copy link
Contributor

@danscales danscales commented Jan 26, 2022

Thanks for the example. The error message should be fixed in this case, which will be like what it is in Go 1.17. I have a simple fix, but it may wait until after beta-2.

@gopherbot
Copy link

@gopherbot gopherbot commented Jan 28, 2022

Change https://golang.org/cl/381774 mentions this issue: cmd/compile: tweak missingMethodReason logic to improve message

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

No branches or pull requests

4 participants