You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
This is a follow up on #21738. In https://play.golang.org/p/1EnY2XsjDU:
x.f
is valid only if(*x).f
is a valid selector andf
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
inx.f
and to the methodf
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 ofx
is a named pointer type, it ignores methods.go/types correctly rejects
x.f
.The text was updated successfully, but these errors were encountered: