You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The compiler will emit a confusing error when a type is shadowed within a function. It should somehow try and make clear that the inner type shadows the global type.
prog.go:13: cannot use Range literal (type Range) as type Range in assignment
Just for the record: There's no "aliasing" going on here - you are declaring a new Range that happens to shadow an outer Range type; not a recommended practice for types.
It's probably a bit of work to make these cases print more information when it makes sense (such as in this one), and not when it's not needed.
griesemer
changed the title
cmd/gc: cannot use Foo literal (type Foo) as type Foo in assignment
cmd/gc: better error message when attempting to use a shadowed type name
Jan 23, 2015
rsc
changed the title
cmd/gc: better error message when attempting to use a shadowed type name
cmd/compile: better error message when attempting to use a shadowed type name
Jun 8, 2015
The compiler will emit a confusing error when a type is shadowed within a function. It should somehow try and make clear that the inner type shadows the global type.
Link to play.golang.org example
Link to golang-nuts thread
See also #8853.
Edit: I incorrectly referred to "shadowing" as "aliasing".
The text was updated successfully, but these errors were encountered: