Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: trying to call init() from a different file should give a more specific error message #23963

Closed
eric-smithson opened this issue Feb 20, 2018 · 3 comments

Comments

Projects
None yet
4 participants
@eric-smithson
Copy link

commented Feb 20, 2018

What version of Go are you using (go version)?

go1.8.3 linux/amd64

Does this issue reproduce with the latest release?

I don't know.

What operating system and processor architecture are you using (go env)?

amd64

What did you do?

I tried to call an init() function from a different go file but within the same package.

What did you expect to see?

I expected more specific feedback about what I did wrong.

What did you see instead?

It just told me that init() wasn't defined. Which was very confusing because I had other lowercase functions I was able to call package-wide no problem. I now know that lowercase init() is a special function but it wasn't obvious from the error message.

@eric-smithson

This comment has been minimized.

Copy link
Author

commented Feb 20, 2018

Also if someone could be inclined to tell me how to fix this I'd like to try fixing this myself. 😛

@bradfitz bradfitz changed the title Trying to call init() from a different file should give a more specific error message cmd/compile: trying to call init() from a different file should give a more specific error message Feb 20, 2018

@bradfitz bradfitz added the NeedsFix label Feb 20, 2018

@bradfitz bradfitz added this to the Go1.11 milestone Feb 20, 2018

@bradfitz

This comment has been minimized.

Copy link
Member

commented Feb 20, 2018

Seems like a reasonable request, especially as Go tries to have nice error messages.

I don't see that two files are relevant to this bug, though. It seems to have the same error message regardless of file:

bradfitz@gdev:~/src/issue23963$ cat file1.go 
package foo
 
func init() {
}
 
func one() {
        init()
}
bradfitz@gdev:~/src/issue23963$ cat file2.go 
package foo
 
func f() {
        init()
}
bradfitz@gdev:~/src/issue23963$ go build
# issue23963
./file1.go:7:2: undefined: init
./file2.go:4:2: undefined: init

/cc @griesemer @mdempsky @odeke-em

@griesemer

This comment has been minimized.

Copy link
Contributor

commented Feb 20, 2018

Not related to calling from a different file. The same error appears when calling from the same file. Also, not entirely trivial to fix nicely. Also, duplicate of #8481. Closing in favor of #8481.

@griesemer griesemer closed this Feb 20, 2018

@golang golang locked and limited conversation to collaborators Feb 20, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.