back

by porridgeraisin·1y ago·view on hn ↗
This is fairly standard and expected behaviour. Embedded pointers get copied only when you explicitly do a deep copy.
1 comments
yes, however if you look at the function definition then you can't tell if the caller is passing a slice vs an array, or an interface that is implemented on a pointer vs a struct.

The semantics of the function parameter should not depend on how the function is being called.

> if you look at the function definition then you can't tell if the caller is passing a slice vs an array

You certainly can. If a function is `f(x []int)` it is illegal to pass a `[3]int` to it. And vice versa, if a parameter is `[3]int` you cannot pass in an `[]int` there.

> or an interface that is implemented on a pointer vs a struct. The semantics of the function parameter should not depend on how the function is being called.

In this case, the semantics of the parameter is the semantics of the interface in question. Whether that interface is implemented by a value or implemented by a pointer inside a particular user of the function is not relevant. This is good -- the decision of using pointer or value receivers on the user's struct, of course, should rest with the user.