Skip to content

range-val-in-closure: incorrectly flags struct key if the key has the same name as a range variable #637

Closed
@twmb

Description

@twmb
package main

type t struct {
	key string
}

func main() {
	m := map[string]string{
		"a": "b",
	}

	for key := range m {
		myKey := key
		go func() {
			println(t{key: myKey})
		}()
	}
}
junk.go:15:14: range-val-in-closure: loop variable key captured by func literal (revive)
			println(t{key: myKey})

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions