Thank you Jan, this helped me a lot.

Unfortunately, the connection between "predeclared" (or "implicitly declared" 
as the first paragraph says) and "defined" is not at all obvious. Especially as 
the definition of "defined type" refers to types explicitly declared via the 
"type" keyword.

I conclude that the difference between assigning int to number (which fails) 
and *int to intp (which works) in the original example is subtle, well hidden 
in the spec, and probably quite difficult to explain to newcomers. (Especially 
the logic behind it.)
On 8. May 2020, 16:01 +0200, Jan Mercl <0xj...@gmail.com>, wrote:
> On Fri, May 8, 2020 at 3:29 PM Christoph Berger
> <christophberger....@gmail.com> wrote:
>
> > So I conclude that the assignment of *int to intp succeeds because *int is 
> > not a defined type and both *int and intp have the same underlying type 
> > *int.
> >
> > Looking through the ref spec I found a couple of places that mention some 
> > defined types (esp., all numeric types and string). Is there an exhaustive 
> > list available of all predefined types that technically count as defined 
> > types?
>
> Predeclared types are listed here:
> https://golang.org/ref/spec#Predeclared_identifiers in the section
> "Types:"
>
> Note that they do not "technically count". If 'name' is binded to a
> type in a declaration then type 'name' is a defined type. The rule is
> universal. The difference is that eg. `*int` is not a name
> (identifier), so it's a type literal defining a pointer to a
> named/defined type.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/74fa0bfa-9611-48b3-a173-0ebdbacd1315%40Spark.

Reply via email to