After a rebase and refactor of a large-ish codebase, I found myself
staring at this odd compiler error:
> prog.go:13: cannot use Range literal (type Range) as type Range in assignment
I eventually found the bug, but the message was hard to interpret,
since it sounds impossible. It turned out that the type was being
aliased inside the function. This wasn't immediately clear - it was
obscured by the "fog of rebase".
I was wondering if it's possible to fix the message somehow to make it
clearer that one of those "Ranges" mentioned in the error is not like
the other?
Playground:
http://play.golang.org/p/ljMvbQf_WC
Code:
package main
type Range struct{ Start, End int }
type Foo struct{ rng Range }
func main() {
type Range struct{ Start, End int }
foos := []Foo{}
for i, foo := range foos {
foos[i].rng = Range{}
}
}