I’m learning Go and was checking if Go supports function overloading. Go does not support function overloading, which is fine. But, the compiler generates inconsistent error messages for function overloading.
If you overload a function, the compiler will rightly identify the previous declaration. But, in the function invocations, it complains on the invocations of the first declaration and not the last.
One would expect it to complain on the redeclaration and invocations of the redeclarations.
./prog.go:11:6: f redeclared in this block
prog.go:7:6: previous declaration
./prog.go:16:6: f redeclared in this block
prog.go:11:10: previous declaration
./prog.go:23:3: not enough arguments in call to f
have ()
want (int, int)
./prog.go:24:3: not enough arguments in call to f
have (number)
want (int, int)
Go build failed.
Here’s another example with variable redeclarations instead of function redeclarations.