no returned name or package path from reflect.Type?

45 views
Skip to first unread message

Dan Kortschak

unread,
Nov 22, 2019, 4:06:50 PM11/22/19
to golang-nuts
Are reflect.Type.PkgPath/Name supposed to return strings for defined
types? There's nothing in the documentation that says they don't.

But https://play.golang.org/p/8Jede-mimtA and
https://play.golang.org/p/LT5m6yz0P5Y don't show any output where I
would expect them to.

Dan



Ian Lance Taylor

unread,
Nov 22, 2019, 8:01:55 PM11/22/19
to Dan Kortschak, golang-nuts
You have to be careful when using reflect with interface types. And a
pointer to a defined type doesn't have a name. Consider

https://play.golang.org/p/oXF6Ems5q_q

https://play.golang.org/p/dKHBkYyfVF6

Ian

Dan Kortschak

unread,
Nov 22, 2019, 8:06:21 PM11/22/19
to golang-nuts
Solved. Because they are not named types (being the pointer to the
type).

Dan Kortschak

unread,
Nov 22, 2019, 9:08:34 PM11/22/19
to Ian Lance Taylor, golang-nuts
Thanks. That continues to trip me up.
Reply all
Reply to author
Forward
0 new messages