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/go: incorrect errors from 'go run' #3490

Closed
gopherbot opened this issue Apr 7, 2012 · 3 comments
Closed

cmd/go: incorrect errors from 'go run' #3490

gopherbot opened this issue Apr 7, 2012 · 3 comments
Milestone

Comments

@gopherbot
Copy link

by acmmlyc:

1. Download `sample.go`, attached. It uses "sql/database/driver" instead of
"database/sql/driver" to illustrate the point.
2. `go build sample.go`
3. `go run sample.go`

What is the expected output?

    $ go build sample.go
    sample.go:3:8: import "sql/database/driver": cannot find package
    $ go run sample.go
    # command-line-arguments
    sample.go:3:8: import "sql/database/driver": cannot find package
    $

(or similar.)

What do you see instead?

    $ go build sample.go
    sample.go:3:8: import "sql/database/driver": cannot find package
    $ go run sample.go
    # command-line-arguments
    sample.go:3: imported and not used: "sql/database/driver"
    sample.go:5: undefined: driver
    $

Which compiler are you using (5g, 6g, 8g, gccgo)?

gc (weekly.2012-03-27).

Which operating system are you using?

OS X (10.7.3).

Attachments:

  1. sample.go (134 bytes)
@rsc
Copy link
Contributor

rsc commented Apr 9, 2012

Comment 1:

There are two bugs here.
1. 'go run' is incorrectly ignoring errors that happen during the load.  You can see the
error in 'go list -json sample.go', and go run should report it.  Perhaps it is ignoring
it because it appears in DepsErrors and not in Error.  Fixing this alone would fix the
problem, making go run print the same error that go build does.
2. Because 'go run' ignores the errors, it actually tries to build the fictitious
sql/database/driver package, and the build succeeds in creating an empty .a file.  The
existence of this .a file that keeps 6g from reporting the invalid import and instead
causes the other two errors.  You can see the build in the output of 'go run -x
sample.go'.  Any build of a package with no .go files should fail.  (It should never
happen but it should still fail.)

Labels changed: added priority-soon, go1.1, removed priority-triage.

Status changed to Accepted.

@ality
Copy link
Member

ality commented Apr 28, 2012

Comment 2:

Fix is here: https://golang.org/cl/6139046/

Owner changed to @ality.

Status changed to Started.

@rsc
Copy link
Contributor

rsc commented Apr 30, 2012

Comment 3:

This issue was closed by revision 84ce0f7.

Status changed to Fixed.

@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1 label Apr 14, 2015
rsc pushed a commit that referenced this issue May 11, 2015
««« backport 1d4d8324085b
cmd/go: do not ignore DepsErrors in 'go run'

Fixes #3490.

R=golang-dev, dave, rsc
CC=golang-dev
https://golang.org/cl/6040046

»»»
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants