Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Types are incorrect when omitting the value while ranging over a slice #72

Open
m90 opened this issue Sep 26, 2017 · 0 comments
Open

Types are incorrect when omitting the value while ranging over a slice #72

m90 opened this issue Sep 26, 2017 · 0 comments

Comments

@m90
Copy link

m90 commented Sep 26, 2017

This is picking up: microsoft/vscode-go#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant