All agreed, Jan. I have not meant to indicate that the definition of "defined type" is incorrect or complicated. The problem lies in the fact that a type like int, that is commonly recognized as a built-in type, happens to be a "defined type". This, plus the fact that a pointer to int is not a defined type, and thus two seemingly similar assignments obey to different rules.
I started this thread as I need to explain to someone if they can assign cmdline flags to defined types. With the flag functions that return pointers it is possible, with the *Var variations (IntVar, StringVar) it is not. This is quite difficult to explain without having to admit that the type system is not that straightforward as it might seem for a language like Go. I know, a static type system is never easy, and AFAIR, even Eiffel's type system is not entirely consistent, but still... On 8. May 2020, 16:42 +0200, Jan Mercl <0xj...@gmail.com>, wrote: > On Fri, May 8, 2020 at 4:31 PM Christoph Berger > <christophberger....@gmail.com> wrote: > > > 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. > > The definition of "defined type" is correct and simple, no special > rules exists. The predeclared identifier `int` is declared that way, > except it's done by the compiler without the need to do it in user > code. See here: https://godoc.org/builtin#int > > Of course, the builtin package is only a formal definiton, it has > special treatment by the compiler, so doing the same in user code > would be invalid. Still `int` is defined and treated as `type int > something` and it's thus a defined(named) type. > > In the first approximation, any type represented by a name is a > defined type. Later came type aliases, so now it's a bit more > complicated b/c one can write also `type T = []U` where T is not a > defined type b/c []U is not a 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/69eb2892-3e17-439a-a1ce-97c5baaf6dec%40Spark.