-
Notifications
You must be signed in to change notification settings - Fork 18k
Type assertion for embedded structs fails when interface name equals function name #42333
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
Comments
Methods from embedded things can only be promoted when they are unambiguous. |
I get your point but that's still a little confusing. I would argue that |
It may help to read through the recent discussions about embedding, such as #6977 /cc @griesemer |
This is working as expected. A simpler example will make this clearer: package main
type M interface {
M()
}
type S struct {
M
}
func main() {
var _ M = S{}
} The type
Consequently, if we try to see if an empty interface holding an Changing the method name from I agree that this can be confusing. Embedding is one of the most complicated parts of Go. Advice: Don't name methods the same as fields (or in this case, types). Closing as working as expected. PS: Just a friendly reminder that it helps to whittle down examples to the bare minimum when filing issues. Often it makes it clear what's wrong and the issue doesn't need to be filed in the first place. And if it is filed, it helps us to get to the core more quickly because we don't have to simplify the example first to see what's going on. Thanks. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Create an interface with embedded function of identical name and type-assert for the interface name.
Working:
Not working:
See https://play.golang.org/p/2MFegoWq5MU. The patterns of the Decorator and Func3 interface are identical. While Decorator type assertion is positive, Func3 ist not. There is no compile error either.
What did you expect to see?
Positive type assertion if interface is implemented.
What did you see instead?
Type assertion false.
The text was updated successfully, but these errors were encountered: