Description
[Apologies if this is a dupe -- couldn't find it.]
This proposal is to automatically take the pointer address (i.e., apply the & operator) of any non-pointer parameters that are passed to function arguments declared as pointers. This would make the behavior for the rest of the arguments consistent with the behavior for the receiver arg in a method.
When calling a method that is declared with a pointer receiver, the compiler automatically takes the address of a non-pointer variable.
Likewise, it would be more consistent, and convenient, if the compiler also automatically took the address of non-pointer parameters passed to pointer args. This would effectively mimic the behavior of the reference type from C++, without introducing any new syntax, and would not affect the ability to compile existing Go1 code as it is just turning what is currently an error into a valid function call.
Example:
func (r *MyType) MyFunc(oth *OtherType) {
...
}
...
a := MyType{}
b := OtherType{}
a.MyFunc(b) // compiled as: a.MyFunc(&b)
...