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

Closed
ThisGuyCodes opened this issue Mar 7, 2016 · 8 comments
Closed

cmd/compile: "dot import" causes confusing error in 1.6 #14683

ThisGuyCodes opened this issue Mar 7, 2016 · 8 comments
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@ThisGuyCodes
Copy link

  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 "do import" causes confusing error in 1.6 "dot import" causes confusing error in 1.6 Mar 7, 2016
@ianlancetaylor ianlancetaylor changed the title "dot import" causes confusing error in 1.6 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
Copy link
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
Copy link
Contributor

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 quentinmit added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label May 26, 2016
@quentinmit
Copy link
Contributor

@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
Copy link
Author

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
Copy link
Contributor

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

@rsc
Copy link
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.

@rsc rsc modified the milestones: Go1.8, Go1.7 May 27, 2016
@rsc rsc modified the milestones: Go1.9, Go1.8 Oct 21, 2016
@rsc rsc added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. labels Oct 21, 2016
@randall77 randall77 modified the milestones: Go1.10, Go1.9 May 31, 2017
@bradfitz
Copy link
Contributor

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
@gopherbot
Copy link

Change https://golang.org/cl/174130 mentions this issue: cmd/go: fix import current directory error message

@golang golang locked and limited conversation to collaborators May 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

7 participants