-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Description
I'm enjoying having the offset-within-the-line information printed in the compiler errors, because my editor is set up to jump to the exact position being printed, which is really very nice.
But I found an example where the offset seems to be wrong:
package p
var s string
func f(x, y, z int) int
func g() int {
return f("hello", s, "world")
return f(s, "hello", "world")
}
Every argument to f in the two return statements is wrong: f takes ints and they're all strings.
$ go tool compile /tmp/x.go
/tmp/x.go:8:11: cannot use "hello" (type string) as type int in argument to f
/tmp/x.go:8:11: cannot use s (type string) as type int in argument to f
/tmp/x.go:8:23: cannot use "world" (type string) as type int in argument to f
/tmp/x.go:9:10: cannot use s (type string) as type int in argument to f
/tmp/x.go:9:14: cannot use "hello" (type string) as type int in argument to f
/tmp/x.go:9:23: cannot use "world" (type string) as type int in argument to f
While the offsets printed for the literal strings are correct, the offsets for the variable s are not. On line 8, the error about s reuses the position of the literal "hello". On line 9, the error about s seems to use the position of the opening parenthesis on the call.
In a real program I noticed this as:
./buildid.go:42:20: cannot use f (type *os.File) as type string in argument to readBinary
./buildid.go:42:20: cannot use name (type string) as type *os.File in argument to readBinary
The arguments - both variables of different types - had been swapped and yet the position reported was the same for both. In this case the errors reported the initial parenthesis twice instead of the beginning of each bad argument.
/cc @griesemer @mdempsky