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: "dot import" causes confusing error in 1.6 #14683

Open
ThisGuyCodes opened this Issue Mar 7, 2016 · 7 comments

Comments

Projects
None yet
7 participants
@ThisGuyCodes

ThisGuyCodes commented Mar 7, 2016

  1. What version of Go are you using (go version)?
    1.6
  2. What operating system and processor architecture are you using (go env)?
    amd64 all around. Reproduced identical output in both Ubuntu (well, mint) and OSX 10.11.
  3. What did you do?
$ go get github.com/conslo/badlink
$ cd $GOPATH/src/github.com/conslo/badlink
$ go install
$ go test
  1. What did you expect to see?
PASS
ok      github.com/conslo/badlink       0.001s
  1. What did you see instead?
# testmain
/usr/local/go/pkg/tool/linux_amd64/link: cannot open file /usr/local/go/pkg/linux_amd64/github.com/conslo/badlink.a: open /usr/local/go/pkg/linux_amd64/github.com/conslo/badlink.a: no such file or directory
FAIL    github.com/conslo/badlink [build failed]

@davecheney and I have already had a bit of a back and forth on this already on golang-nuts (I'll avoid actually requiring anyone to read this, but for attribution sake it's here). It seems if I replace the dot import in the test file (badlink_test.go):

import "."

with a full import:

import "github.com/conslo/badlink"

It fixes it. However the dot import did (and still does) work in 1.5.3.

Dave thinks the dot import should be a compiler error. I agree. However I'm a bit confused as to the state of relative imports in go. I held they were a deliberate omission, but there's mention of limited support which I don't know the details of. And again, this does work in 1.5.3, so unless I screwed something else up (repeatedly, on different machines) this is a regression.

Possibly related?:
#14609

For the record, I don't generally like relative imports, but saw the dot import in tests at a talk and thought that it seemed like a nice exception. A way for a _test package to say "I'm testing myself". But I'd be happy if this was just a more clear error.

@ThisGuyCodes ThisGuyCodes changed the title from "do import" causes confusing error in 1.6 to "dot import" causes confusing error in 1.6 Mar 7, 2016

@ianlancetaylor ianlancetaylor changed the title from "dot import" causes confusing error in 1.6 to cmd/compile: "dot import" causes confusing error in 1.6 Mar 7, 2016

@ianlancetaylor ianlancetaylor added this to the Go1.7 milestone Mar 7, 2016

@rsc

This comment has been minimized.

Contributor

rsc commented May 17, 2016

import "." should not work. The error here should be changed to something like "cannot import current directory". That's probably still doable for Go 1.7.

@ianlancetaylor

This comment has been minimized.

Contributor

ianlancetaylor commented May 19, 2016

We actually have tests in cmd/go/go_test.go that verify that import "." works. See https://golang.org/src/cmd/go/testdata/local/easysub/main.go .

@quentinmit

This comment has been minimized.

Contributor

quentinmit commented May 26, 2016

@rsc In light of the explicit test to make sure this works, do we still want to continue to treat this as an error?

@ianlancetaylor If we have explicit tests for this, why are they not failing?

@ThisGuyCodes

This comment has been minimized.

ThisGuyCodes commented May 26, 2016

@quentinmit it works when you use go run somefile.go, but not with go install. Since the test in question has the main.go (package main) in the same folder as the easysub package it's importing, I imagine that's how it's being run.

(edit: corrected go build to go install)

@ianlancetaylor

This comment has been minimized.

Contributor

ianlancetaylor commented May 26, 2016

To be pedantically clear, it also works with go build somefile.go which is what cmd/go/go_test.go is testing.

@rsc

This comment has been minimized.

Contributor

rsc commented May 27, 2016

All right, well if there are tests that it should work, then I guess it can stay. The error message here is not critical for Go 1.7.

@bradfitz

This comment has been minimized.

Member

bradfitz commented Nov 29, 2017

The error message is now different at Go tip (as of 992ce90):

bradfitz@gdev:~/src/github.com/conslo/badlink$ go test
# github.com/conslo/badlink
badlink_test.go:6:2: local import "." in non-local package
FAIL    github.com/conslo/badlink [setup failed]

But still not critical.

@bradfitz bradfitz modified the milestones: Go1.10, Go1.11 Nov 29, 2017

@gopherbot gopherbot modified the milestones: Go1.11, Unplanned May 23, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment