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

Open
griesemer opened this Issue Sep 19, 2017 · 2 comments

Comments

Projects
None yet
3 participants
@griesemer
Contributor

griesemer commented Sep 19, 2017

This is a follow up on #21738. In https://play.golang.org/p/1EnY2XsjDU:

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 https://tip.golang.org/ref/spec#Selectors. 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.

@mdempsky

This comment has been minimized.

Member

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.

@mdempsky

This comment has been minimized.

Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment