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
In 1.. when f := &Foo{}, return f should cause an error. My reason is that the struct implemented the interface not the pointer to the struct. Also, in 2., when f := Foo{}, return f causes an error. Why is there a discrepancy in behavior in the two cases. Does this have to do with the memory layout of interfaces, structs and pointers to them or some golang magic behind the scenes.
What did you see instead?
Returning struct and pointer to it both works.
The text was updated successfully, but these errors were encountered:
Pointer receivers imply that an object's state is mutable. An interface that stores a non-pointer type can not modify any fields in the original value, because each method call creates a copy of the value stored in the interface and operates on that. Allowing that to work would likely be very misleading.
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?1.10.3
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?darwin/amd64
What did you do?
What did you expect to see?
In 1.. when f := &Foo{}, return f should cause an error. My reason is that the struct implemented the interface not the pointer to the struct. Also, in 2., when f := Foo{}, return f causes an error. Why is there a discrepancy in behavior in the two cases. Does this have to do with the memory layout of interfaces, structs and pointers to them or some golang magic behind the scenes.
What did you see instead?
Returning struct and pointer to it both works.
The text was updated successfully, but these errors were encountered: