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

errors: Unexpected behavior of errors.As if the struct has the same name as one of its methods #46820

Closed
wendellrios opened this issue Jun 18, 2021 · 2 comments

Comments

@wendellrios
Copy link

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

$ go version
 go1.15 linux/amd64

Does this issue reproduce with the latest release?

yes

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

go env Output
$ go env

What did you do?

https://play.golang.org/p/gWmNCTUMtau

What did you expect to see?

PASS: TestCanEmbedPointerIfTypeNameIsEqualMethodName

What did you see instead?

prog.go:40: B is not an UE, but it should be. I believe this is an error in the library.

--- FAIL: TestCanEmbedPointerIfTypeNameIsEqualMethodName (0.00s)

@wendellrios wendellrios changed the title Unexpected behavior or error.As if the struct has the same name as one of its methods errors: Unexpected behavior of errors.As if the struct has the same name as one of its methods Jun 18, 2021
@tmthrgd
Copy link
Contributor

tmthrgd commented Jun 18, 2021

This is how the language works. In your second test the embedded field and method conflict so the method isn’t promoted. B really doesn’t have a UserError method.

If you try and call it manually you’ll see something like:

cannot call non-function new(B).UserError (type *UserError)

@ianlancetaylor
Copy link
Contributor

Closing because there is no bug here.

@golang golang locked and limited conversation to collaborators Jun 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants