You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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).
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.)
by acmmlyc:
Attachments:
The text was updated successfully, but these errors were encountered: