(had a look, couldn't recall this having been discussed or raised before)
Consider the following code:
package main
import (
"fmt"
)
type S struct {
Name string
}
func (s S) SetName(n string) {
s.Name = n
}
type NameSet interface {
SetName(n string)
}
func main() {
s1 := S{}
var s2 NameSet = s1
s1.Name = "Rob"
fmt.Printf("s1: %v, s2: %v\n", s1, s2)
s2.SetName("Pike")
fmt.Printf("s1: %v, s2: %v\n", s1, s2)
}
Per the Go Playground, this should output:
s1: {Rob}, s2: {}
s1: {Rob}, s2: {}
But per the GopherJS Playground we get:
s1: {Rob}, s2: {Rob}
s1: {Pike}, s2: {Pike}
Reason being the assignment to s2 is not $clone-ing the value from s1.
Similarly, in the call s2.SetName we are not $clone-ing.
If the type of s2 is changed to S then everything works as expected.
Will look into this a bit more later, just logging here for now.