golang`range`关键字是否可以输入类型信息?

Consider this golang program:

func main() {
    one := uint(1)
    ones := []uint{1, 1, 1}
    for x := range ones {
        if x != one {
            print("ERR")
        }
    }
}

When I try to compile I get an unexpected error:

$ go build foo.go 
# command-line-arguments
./foo.go:7: invalid operation: x != one (mismatched types int and uint)

Why does go think x has type int instead of uint?

The first value returned by range is the index, not the value. What you need is:

func main() {
    one := uint(1)
    ones := []uint{1, 1, 1}
    for _, x := range ones {
        if x != one {
            print("ERR")
        }
    }
}