godef
godef copied to clipboard
Types are incorrect when omitting the value while ranging over a slice
This is picking up: https://github.com/Microsoft/vscode-go/issues/1242
I found an issue in godef where the first argument when ranging over a slice will be incorrect when you omit the value (i.e. use the index only).
Consider the following program:
package main
import (
"fmt"
)
func main() {
s := []string{"a", "b", "c"}
for index, char := range s {
fmt.Println(index, char)
}
for index := range s {
fmt.Println(index)
}
}
I will get int, string for the first loop, but bool for the second one:
frederik@fr-xps:~/projects/go/src/github.com/m90/test$ cat main.go
package main
import (
"fmt"
)
func main() {
s := []string{"a", "b", "c"}
for index, char := range s {
fmt.Println(index, char)
}
for index := range s {
fmt.Println(index)
}
}
frederik@fr-xps:~/projects/go/src/github.com/m90/test$ godef -o 84 -f main.go -t
main.go:9:6
index int
frederik@fr-xps:~/projects/go/src/github.com/m90/test$ godef -o 89 -f main.go -t
main.go:9:13
char string
frederik@fr-xps:~/projects/go/src/github.com/m90/test$ godef -o 144 -f main.go -t
main.go:12:6
index bool