2 ms·
This code is illegal in Go item := item item := item "no new variables on left side of :=" You can't declare the same variable twice in the same scop
by ithkuil 4y ago
This code is illegal in Go
item := item
item := item
"no new variables on left side of :="
You can't declare the same variable twice in the same scope.
item := item
works only because it declares a new variable in the current scope, initialized with a variable with the same name (but different variable) from the outer scope.
Go distinguishes declarations from assignments. In this example, the second assignment is a no-op indeed.
item := item
item = item
- valenterry 4y agoOkay fair enough, thx for the explanation. Doesn't make it good, but better!