Explained in proposal 
<https://go.googlesource.com/proposal/+/master/design/18130-type-alias.md>:

<https://go.googlesource.com/proposal/+/master/design/18130-type-alias.md#type-cycles>Type
 
> cycles
>
> In a type alias declaration, in contrast to a type declaration, T2 must 
> never refer, directly or indirectly, to T1. For example type T = *T and type 
> T = struct { next *T } are not valid type alias declarations. In 
> contrast, if the equals signs were dropped, those would become valid 
> ordinary type declarations. The distinction is that ordinary type 
> declarations introduce formal names that provide a way to describe the 
> recursion. In contrast, aliases must be possible to “expand out”, and there 
> is no way to expand out an alias like type T = *T.
>


суббота, 8 декабря 2018 г., 20:33:48 UTC+3 пользователь Jan Mercl написал:
>
> This code compiles fine
>
>         package main
>         
>         type node struct {
>                 next *node
>         }
>         
>         func main() {}
>
> (https://play.golang.org/p/ZYg0EciQnOQ)
>
> This code does not
>
>         package main
>         
>         type node = struct {
>                 next *node
>         }
>         
>         func main() {}
>
> (https://play.golang.org/p/gWWX8ngPsS6)
>
> The error is
>
>         prog.go:3:6: invalid recursive type alias node
>                 prog.go:3:6: node uses <T>
>                 prog.go:3:13: <T> uses node
>
> The specification remains silent about what is considered "invalid 
> recursive type alias" so I'm not sure, but it seems to me the first and 
> second programs should both compile fine. In both cases, so to say "the 
> pointer breaks the cycle" while type checking. But maybe/probably I'm 
> mistaken.
>
> Can anybody enlighten me please and explain if the compiler is right or if 
> it's a bug?
>
> Thanks in advance.
>
> -- 
>
> -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.

Reply via email to