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

x/tools/gopls: bad import causes test-exported values to be "not declared by package" #34012

Closed
zikaeroh opened this issue Sep 2, 2019 · 5 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@zikaeroh
Copy link
Contributor

zikaeroh commented Sep 2, 2019

What did you do?

In a module example.org/library, library.go:

package library

var offset = 0

func Add(a, b int) int {
	return a + b + offset
}

export_test.go:

package library

func Offset(x int) {
	offset = x
}

library_test.go:

package library_test

import (
	"flags"
	"testing"

	"example.org/library"
)

var badFlag = flags.Bool("bad", false, "this doesn't work")

func TestAdd(t *testing.T) {
	library.Offset(1)
	got := library.Add(1, 2)
	want := 3
	if got != want {
		t.Fatalf("Add(1, 2) = %d, want %d", got, want)
	}
}

And open library_test.go.

What did you expect to see?

flags is not the correct name for the flag package, and it correctly has an error saying "could not import flags". That is the only error.

What did you see instead?

In addition to the error on flags and its usage, Offset in library.Offset(1) has the error "Offset not declared by package library", which is not true. Removing the bad import or fixing it does not make the Offset error go away; only a full reload does.

Unfortunately, after "fixing it", gopls hangs (both master and 0.1.3), even the gopls -rpc.trace -v check is broken, even though the code was changed back to what was written above.

2019/09/01 18:52:40 Info:Build info
----------
golang.org/x/tools/gopls v0.1.2
    golang.org/x/tools/gopls@v0.1.3 h1:CB5ECiPysqZrwxcyRjN+exyZpY0gODTZvNiqQi3lpeo=
    golang.org/x/sync@v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
    golang.org/x/tools@v0.0.0-20190710153321-831012c29e42 h1:4IOeC7p+OItq3+O5BWkcmVu2uBe3jekXau5S4QZX9DU=

Go info
-------
go version go1.12.9 linux/amd64

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/jake/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/jake/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/go"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/jake/testproj/testexportbug/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build176526797=/tmp/go-build -gno-record-gcc-switches"
2019/09/01 18:52:40 Error:unable to check package for file:///home/jake/testproj/testexportbug/library_test.go: go/packages.Load: no packages found for /home/jake/testproj/testexportbug/library_test.go
2019/09/01 18:52:40 Error:unable to check package for file:///home/jake/testproj/testexportbug/library_test.go: go/packages.Load: no packages found for /home/jake/testproj/testexportbug/library_test.go
^C

master:

2019/09/01 18:54:40 Info:2019/09/01 18:54:40 10.319133ms for GOROOT= GOPATH=/home/jake/go GO111MODULE= PWD=/home/jake/testproj/testexportbug go "env" "GOMOD", stderr: <<>>
2019/09/01 18:54:40 Info:2019/09/01 18:54:40 10.5124ms for GOROOT= GOPATH=/home/jake/go GO111MODULE= PWD=/home/jake/testproj/testexportbug go "list" "-m" "-json" "all", stderr: <<>>
2019/09/01 18:54:40 Info:2019/09/01 18:54:40 11.331915ms for GOROOT= GOPATH=/home/jake/go GO111MODULE= PWD=/home/jake/testproj/testexportbug go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "builtin", stderr: <<>>
2019/09/01 18:54:40 Info:2019/09/01 18:54:40 Build info
----------
golang.org/x/tools/gopls v0.1.3
    golang.org/x/tools/gopls@v0.1.4-0.20190830223141-573d9926052a h1:GHSDcXHHvdapqqDYPriYzm7tvh64EQYFlmHI/MvS/yg=
    golang.org/x/sync@v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
    golang.org/x/tools@v0.0.0-20190830223141-573d9926052a h1:XAHT1kdPpnU8Hk+FPi42KZFhtNFEk4vBg1U4OmIeHTU=
    golang.org/x/xerrors@v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc=

Go info
-------
go version go1.12.9 linux/amd64

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/jake/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/jake/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/go"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/jake/testproj/testexportbug/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build345591434=/tmp/go-build -gno-record-gcc-switches"
2019/09/01 18:54:40 Info:2019/09/01 18:54:40 9.662061ms for GOROOT= GOPATH=/home/jake/go GO111MODULE= PWD=/home/jake/testproj/testexportbug go "env" "GOMOD", stderr: <<>>
2019/09/01 18:54:40 Info:2019/09/01 18:54:40 10.189479ms for GOROOT= GOPATH=/home/jake/go GO111MODULE= PWD=/home/jake/testproj/testexportbug go "list" "-m" "-json" "all", stderr: <<>>
2019/09/01 18:54:40 Info:2019/09/01 18:54:40 18.299807ms for GOROOT= GOPATH=/home/jake/go GO111MODULE= PWD=/home/jake/testproj/testexportbug go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "/home/jake/testproj/testexportbug", stderr: <<>>
2019/09/01 18:54:40 failed to compute diagnostics: go/packages.Load: no packages found for /home/jake/testproj/testexportbug/library_test.go
	file = file:///home/jake/testproj/testexportbug/library_test.go
2019/09/01 18:54:40 Error:2019/09/01 18:54:40 failed to compute diagnostics: go/packages.Load: no packages found for /home/jake/testproj/testexportbug/library_test.go
	file = file:///home/jake/testproj/testexportbug/library_test.go
^C

Build info

golang.org/x/tools/gopls v0.1.3
    golang.org/x/tools/gopls@v0.1.4-0.20190830223141-573d9926052a h1:GHSDcXHHvdapqqDYPriYzm7tvh64EQYFlmHI/MvS/yg=
    golang.org/x/sync@v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
    golang.org/x/tools@v0.0.0-20190830223141-573d9926052a h1:XAHT1kdPpnU8Hk+FPi42KZFhtNFEk4vBg1U4OmIeHTU=
    golang.org/x/xerrors@v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc=

Built on master just to keep it recent, but happens on 0.1.3 and has on previous versions as well.

Go info

go version go1.12.9 linux/amd64

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/jake/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/jake/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/go"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/jake/testproj/testexportbug/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build336388165=/tmp/go-build -gno-record-gcc-switches"
@gopherbot gopherbot added the gopls Issues related to the Go language server, gopls. label Sep 2, 2019
@gopherbot
Copy link

Thank you for filing a gopls issue! Please take a look at the Troubleshooting section of the gopls Wiki page, and make sure that you have provided all of the relevant information here.

@zikaeroh zikaeroh changed the title gopls: bad import causes test-exported values to be "not declared by package" x/tools/gopls: bad import causes test-exported values to be "not declared by package" Sep 2, 2019
@gopherbot gopherbot added this to the Unreleased milestone Sep 2, 2019
@stamblerre stamblerre added the Tools This label describes issues relating to any tools in the x/tools repository. label Sep 9, 2019
@stamblerre
Copy link
Contributor

CL 201539 should have handled this case. @zikaeroh: Are you still able to reproduce this error at master?

@zikaeroh
Copy link
Contributor Author

I will recheck and see with my example, though the current master is very, very broken for me and I've had to go back to d2fffb4 in the meantime until I can file a proper issue for the new breakage.

@zikaeroh
Copy link
Contributor Author

Actually, the current behavior is even weirder than the original error case. If I do exactly my instructions, "flags" has no diagnostics to say that the package does not exist, and I do not seem to get any completion when modifying the file.

@zikaeroh
Copy link
Contributor Author

zikaeroh commented Dec 7, 2019

It's been over a month; I've just retested this and I get the expected behavior. Not sure which CL fixed it, but it's fixed nevertheless.

@zikaeroh zikaeroh closed this as completed Dec 7, 2019
@stamblerre stamblerre modified the milestones: gopls/v1.0.0, gopls/v0.4.0 Jul 22, 2020
@golang golang locked and limited conversation to collaborators Jul 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants