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
Does this issue reproduce with the latest release?
the detail code
type A interface {
A()
//OtherA()
}
type a struct {
}
func (a *a) A() {
fmt.Println("a")
}
func (a *a) OtherA() {
fmt.Println("otherA")
}
type B interface {
A
Other()
}
type b struct {
A
}
func (b *b) Other() {
fmt.Println("other")
}
func PrintAB(b B) {
b.A()
//b.OtherA()
b.Other()
}
func main() {
PrintAB(&b{A: &a{}})
}
build the code, output:
./main.go:44:10: cannot use &b{…} (value of type *b) as type B in argument to PrintAB:
*b does not implement B (missing A method)
The editor does not prompt syntax errors, but this code doesn't compile. If I change the A method to the OtherA in the A interface, it can compile successfully.
What operating system and processor architecture are you using (go env)?
go env Output
$ go env
What did you do?
What did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered:
The type *b has a field named A. That is, (*b).A refers to the field A. It's true that that that field has a method A that could be promoted to the type *b, but the field A shadows the method A.
In general we do not use the issue tracker for questions about the language. If you want to discuss this further, please use a forum; see https://go.dev/wiki/Questions. Thanks.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
the detail code
build the code, output:
The editor does not prompt syntax errors, but this code doesn't compile. If I change the
A
method to theOtherA
in theA
interface, it can compile successfully.What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered: