The error seems correct to me. From the spec: "The scope of a type identifier declared inside a function begins at the identifier in the TypeSpec and ends at the end of the innermost containing block."
So the type declaration in main is a recursive type - the T it refers to is not the previously defined T, but the T being defined on that line. So main.T has no relationship with the globally scoped T, hence `w = &v` is invalid. On 10 May 2018 at 09:33, Jan Mercl <0xj...@gmail.com> wrote: > This modified example from another thread does not compile: > > package main > > import ( > "fmt" > ) > > type T int > > func main() { > var v T > type T *T > var w T > w = &v > *w = v > fmt.Printf("%T %T\n", v, w) > } > > https://play.golang.org/p/3wos23oim0I > > The compiler says > > prog.go:13:4: cannot use &v (type *T) as type T in assignment > prog.go:14:5: cannot use v (type T) as type T in assignment > > It seems like a bug to me, but I want to consult here before reporting a new > issue. > > -- > > -j > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.