trouble with package name clashes

11 views
Skip to first unread message

Petar Maymounkov

unread,
Jan 9, 2010, 7:34:25 PM1/9/10
to golang-nuts
I have a project which has a package named "math". While
my package does not collide with Go's math at import, because

import (
a "math"
b "project/math"
)

is ok, a problem occurs in the .go files implementing my math package.
They use Go's math, and so they have to start like this:

package math

import "math"

which causes a compiler error "package cannot import itself".

Does anyone have an elegant work-around? I suppose I am
trying to avoid re-basing the Go library, which would
result in using a non-standard install of Go. This is probably
not a desirable feature to persist.

Thanks,
--Petar

peterGo

unread,
Jan 9, 2010, 8:34:55 PM1/9/10
to golang-nuts
Petar

import "math" is the same as import math "math", which I would expect
to fail in package math. The problem I have is that the following
fails too.

package math

import gomath "math"

func main() {
const pi = gomath.Pi
}

Peter

Russ Cox

unread,
Jan 10, 2010, 5:55:16 PM1/10/10
to Petar Maymounkov, golang-nuts
Does anyone have an elegant work-around? I suppose I am
trying to avoid re-basing the Go library, which would
result in using a non-standard install of Go. This is probably
not a desirable feature to persist.

For now, there is no elegant work-around.  You have to name
your package something other than math if you need to link
the standard math into your program.  That is, in a single program
all the package names (not just import paths) must be unique.
We plan to eliminate this restriction in the next month or so.

Russ

Reply all
Reply to author
Forward
0 new messages