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: selector expression resolves incorrectly for defined pointer types #21934

griesemer opened this issue Sep 19, 2017 · 3 comments


Copy link

@griesemer griesemer commented Sep 19, 2017

This is a follow up on #21738. In

package main

type E struct{ f int }
type T struct{ E }

func (*T) f() int { return 0 }

type P *T

func main() {
	var x P
	_ = x.f
	_ = (*x).f

	_ = (x.f)() // ERROR: cannot call non-function x.E.f (type int)
	_ = ((*x).f)()

x.f is valid only if (*x).f is a valid selector and f resolves to a field (rule 3 in Specifically, x.f and (*x).f denote the same field.

However, cmd/compile appears to refer to the embedded field f in x.f and to the method f in (*x).f.

The selector resolution is inconsistent here. Furthermore, x.f should be disallowed per rule 3 mentioned above. It appears that cmd/compile uses different lookup rules depending on use case: If the type of x is a named pointer type, it ignores methods.

go/types correctly rejects x.f.

Copy link

@mdempsky mdempsky commented Sep 19, 2017

Implementation detail: cmd/compile doesn't find the method f because it's in *T's method set, whereas x has type P with an empty method set.

Copy link

@mdempsky mdempsky commented Nov 29, 2017

Issue was present in Go 1.9. Bumping to Go 1.11.

@mdempsky mdempsky modified the milestones: Go1.10, Go1.11 Nov 29, 2017
@ianlancetaylor ianlancetaylor modified the milestones: Go1.11, Go1.12 Jun 30, 2018
@griesemer griesemer modified the milestones: Go1.12, Go1.13 Dec 11, 2018
@andybons andybons modified the milestones: Go1.13, Go1.14 Jul 8, 2019
Copy link

@gopherbot gopherbot commented Sep 29, 2019

Change mentions this issue: cmd/compile: lookup methods of base type for named pointer type

@gopherbot gopherbot closed this in 0471417 Oct 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.