Axel,

On Tue Sep 21, 2021 at 15:56 CET, Axel Wagner wrote:
> The underlying type is defined recursively
> <https://golang.org/ref/spec#Types>:
>
> Each type T has an underlying type: If T is one of the predeclared
> boolean,
> > numeric, or string types, or a type literal, the corresponding underlying
> > type is T itself. Otherwise, T's underlying type is *the underlying type
> > of the type* to which T refers in its type declaration.
>
>
> (emphasis mine). From a type-system perspective, there is no real
> difference between these two types. The Go type system treats them the
> same.
>
> So, if you need to differentiate between them, you have to go back from
> the
> types-level to the AST level. That's unfortunately a bit difficult,
> AFAIK.
> I think you have to use the `token.Pos` of the `*TypeName` and then
> traverse the `ast.File`s of the package until you find that position.
> That
> should give you an `ast.TypeSpec`, which can tell you if its `Type`
> field
> is an identifier, or a type literal. Not super ergonomic, but AFAIK the
> only way.

ok, thanks for the quick answer.

cheers,
-s

-- 
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/CEFMIPKOYLY5.3L1WQ08C5LPPP%40clrinfopc42.

Reply via email to