Enforcing a type name rather than a variable name

112 views
Skip to first unread message

ju...@sqreen.io

unread,
Jan 3, 2020, 6:28:52 PM1/3/20
to golang-nuts
Hello,

Is there any way to avoid the compilation error "*error is not a type" of this example https://play.golang.org/p/gWNStGSCfTm ?
I understand the variable named `error` hides the type named `error` but is there some other syntax to specify the error type?

I am facing this issue while writing an instrumentation tool: some functions the tool instruments have such signatures, while the tool add Go code referencing the type name, not the variable name.

Thanks for your help

ju...@sqreen.io

unread,
Jan 3, 2020, 6:37:24 PM1/3/20
to golang-nuts
By the way, here is the function having this in package `net`: https://golang.org/src/net/lookup.go#L81

Jan Mercl

unread,
Jan 4, 2020, 8:33:51 AM1/4/20
to ju...@sqreen.io, golang-nuts
On Sat, Jan 4, 2020 at 12:28 AM <ju...@sqreen.io> wrote:
>
> Hello,
>
> Is there any way to avoid the compilation error "*error is not a type" of this example https://play.golang.org/p/gWNStGSCfTm ?
> I understand the variable named `error` hides the type named `error` but is there some other syntax to specify the error type?

No. In every scope a name binds to only one thing. Once a variable
name in an inner scope hides a type name in an outer scope that type
is no more accessible unless it's also aliased to a different name and
that alias is not shadowed as well.
Reply all
Reply to author
Forward
0 new messages