by kemitche · 7y ago · 0 comments
import "foo"
func other() {
shadow var foo string = "bar";
}[0] and go is actually weirder than that — and the opposite way 'round — as `var` doesn't allow any shadowing in the same scope:
var a, b int
var a, c int // fails because it redeclares a in the same block
while `:=` allows same-scope shadowing as long as the overlap is not complete: a, b := foo()
a, b := foo() // fails because no new variable on the left side
a, c := foo() // succeeds
both allow arbitrary shadowing in sub-scopes. a := 2
a = 3
By definition you must have nested scopes to have shadowing. Within the same scope, it's only ever assignment. let a = 2;
let a = 3;
I think you would say the latter shadows the former...There is already a “let” to show you that a variable is being created, adding more verbosity to a feature that, in some sense, is about removing verbosity kinda misses the point, in my opinion.
That said, never say never, but if I was a betting kind of person, I’d bet against it ever being accepted.