Go sometimes doesn’t know the right line number. When it does compilation, most of the time it tells me the correct number of the line that contains an error.
But sometimes it doesn’t, and I have no idea why. There are two problems I get. Go tells me the wrong line number, off by 1. Or: Go only knows only the line number of the opening brace of a function call.
When I have these sorts of problems, usually, I think, it’s when my code calls a function that resides in a package. And the error is usually that I passed an argument that has the wrong type.
And when there are very few arguments that’s okay, but not so when the functions take many arguments. And another thing is that Go never tells me the number of the argument - which is what other compilers usually do, don’t they?
I can’t give an example. It happens every day or week, and I could give an example, but you must have noticed that there is something a bit wrong with Go in this regard?
The very least solution would be trying to tell the user the number of the argument that has the wrong type.
Yep, pretty much like this. Thanks for clarifying it.
PS: In my case today I had passed two nils, so, Go naming the argument didn’t help.
And for some reason the line number was the line containing the function name, a few lines above. Maybe Go has some trouble with line numbers when there are several errors.
So, the problem with two same arguments (c,c,nil,nil,0,0 etc) is, that without getting told which one it is, you need to rely on the line number. That is one issue.
And the line number is off by 1, or by 2, or it’s the line with the function name as in your example. But I never know what the line number will be, so it’s a bit of a guessing game. I wonder if they have any bug filed related to this.