Re: [go-nuts] What does this error mean?

5,943 views
Skip to first unread message

David Symonds

unread,
Aug 24, 2012, 5:17:24 AM8/24/12
to atul, golan...@googlegroups.com
On Fri, Aug 24, 2012 at 5:47 PM, atul <atul...@iclinica.in> wrote:

> If I say
> var t *tree = tree.New(4)
> I get an error...
>
> "./compile19.go:19: use of package tree not in selector"

The compiler is telling you, though perhaps in words you are
unfamiliar with. The identifier "tree" is a package name here
(presumably you have imported "tree" or something), but you are trying
to name a type. You probably want something like
var t *tree.Tree = tree.New(4)

chris dollin

unread,
Aug 24, 2012, 5:19:31 AM8/24/12
to atul, golan...@googlegroups.com
On 24 August 2012 08:47, atul <atul...@iclinica.in> wrote:
> Dear all,
> I started learning go by taking the gotour...
> While running exercise #69
> "Exercise: Equivalent Binary Trees"
>
> If I say
> var t *tree = tree.New(4)
> I get an error...
>
> "./compile19.go:19: use of package tree not in selector"

`tree` is not a type name, it's a package name. I think
you mean *tree.Tree.

> However, if I change the line to
> t := tree.New(4)

(or var t = tree.New(4))

> it works fine..

Because you're not trying to use a package name as
a type name any more. t will get the type that tree.New's
result has.

Chris

--
Chris "allusive" Dollin

minux

unread,
Aug 24, 2012, 5:26:40 AM8/24/12
to atul, golan...@googlegroups.com
On Fri, Aug 24, 2012 at 3:47 PM, atul <atul...@iclinica.in> wrote:
        While running exercise #69
"Exercise: Equivalent Binary Trees"

If I say
         var t *tree = tree.New(4)
I get an error...

"./compile19.go:19: use of package tree not in selector"
tree is a package name (and it's not a type), it can only be used in selectors like this: tree.Tree
if you want to be explicit about the type of t, you can use:
var t *tree.Tree = tree.New(4)

but i think it's not idiomatic (tree.New alone already provides adequate context)

Reply all
Reply to author
Forward
0 new messages