{"action":"opened","issue":{"url":"https://api.github.com/repos/golang/go/issues/28491","repository_url":"https://api.github.com/repos/golang/go","labels_url":"https://api.github.com/repos/golang/go/issues/28491/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/28491/comments","events_url":"https://api.github.com/repos/golang/go/issues/28491/events","html_url":"https://github.com/golang/go/issues/28491","id":375715622,"node_id":"MDU6SXNzdWUzNzU3MTU2MjI=","number":28491,"title":"cmd/go: go list -e -json with syntax error behaves differently in test and non-test files","user":{"login":"myitcv","id":3374574,"node_id":"MDQ6VXNlcjMzNzQ1NzQ=","avatar_url":"https://avatars1.githubusercontent.com/u/3374574?v=4","gravatar_id":"","url":"https://api.github.com/users/myitcv","html_url":"https://github.com/myitcv","followers_url":"https://api.github.com/users/myitcv/followers","following_url":"https://api.github.com/users/myitcv/following{/other_user}","gists_url":"https://api.github.com/users/myitcv/gists{/gist_id}","starred_url":"https://api.github.com/users/myitcv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/myitcv/subscriptions","organizations_url":"https://api.github.com/users/myitcv/orgs","repos_url":"https://api.github.com/users/myitcv/repos","events_url":"https://api.github.com/users/myitcv/events{/privacy}","received_events_url":"https://api.github.com/users/myitcv/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-10-30T22:13:11Z","updated_at":"2018-10-30T22:13:11Z","closed_at":null,"author_association":"MEMBER","body":"Please answer these questions before submitting your issue. Thanks!\r\n\r\n\r\n### What version of Go are you using (`go version`)?\r\n\r\n```\r\ngo version go1.11.1 linux/amd64\r\n```\r\n\r\n### Does this issue reproduce with the latest release?\r\n\r\nYes\r\n\r\n### What operating system and processor architecture are you using (`go env`)?\r\n\r\n```\r\nGOARCH=\"amd64\"\r\nGOBIN=\"\"\r\nGOCACHE=\"/home/myitcv/.cache/go-build\"\r\nGOEXE=\"\"\r\nGOFLAGS=\"\"\r\nGOHOSTARCH=\"amd64\"\r\nGOHOSTOS=\"linux\"\r\nGOOS=\"linux\"\r\nGOPATH=\"/home/myitcv/go-modules-by-example/.gopath\"\r\nGOPROXY=\"\"\r\nGORACE=\"\"\r\nGOROOT=\"/home/myitcv/gos\"\r\nGOTMPDIR=\"\"\r\nGOTOOLDIR=\"/home/myitcv/gos/pkg/tool/linux_amd64\"\r\nGCCGO=\"gccgo\"\r\nCC=\"gcc\"\r\nCXX=\"g++\"\r\nCGO_ENABLED=\"1\"\r\nGOMOD=\"/home/myitcv/go-modules-by-example/go.mod\"\r\nCGO_CFLAGS=\"-g -O2\"\r\nCGO_CPPFLAGS=\"\"\r\nCGO_CXXFLAGS=\"-g -O2\"\r\nCGO_FFLAGS=\"-g -O2\"\r\nCGO_LDFLAGS=\"-g -O2\"\r\nPKG_CONFIG=\"pkg-config\"\r\nGOGCCFLAGS=\"-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build914474323=/tmp/go-build -gno-record-gcc-switches\"\r\n```\r\n\r\n### What did you do?\r\n\r\nThe context of this problem is:\r\n\r\n* https://github.com/stamblerre/gocode, which is the module-aware version of `gocode`, was failing to offer a completion in a `_test.go` file but succeeding in a regular `.go` file with the same content\r\n* This was traced down to a difference in behaviour in `go/packages` \r\n* @ianthehat then suggested we look at the `go list` level; hence this issue and repro\r\n\r\nThe following behaves as expected and lists the `main` package, despite the syntax error in `main.go`:\r\n\r\n```\r\n$ cd $(mktemp -d)\r\n$ go mod init example.com/hello\r\ngo: creating new go.mod: module example.com/hello\r\n$ cat <<EOD >main.go\r\npackage main\r\n\r\nfunc InTest() {\r\n        var x interface{}\r\n        x.\r\n}\r\nEOD\r\n$ go list -e -json .\r\n{\r\n        \"Dir\": \"/tmp/tmp.qlrtnE4Htk\",\r\n        \"ImportPath\": \"example.com/hello\",\r\n        \"Name\": \"main\",\r\n        \"Target\": \"/home/gopher/gopath/bin/hello\",\r\n        \"Module\": {\r\n                \"Path\": \"example.com/hello\",\r\n                \"Main\": true,\r\n                \"Dir\": \"/tmp/tmp.qlrtnE4Htk\",\r\n                \"GoMod\": \"/tmp/tmp.qlrtnE4Htk/go.mod\"\r\n        },\r\n        \"Match\": [\r\n                \".\"\r\n        ],\r\n        \"Stale\": true,\r\n        \"StaleReason\": \"build ID mismatch\",\r\n        \"GoFiles\": [\r\n                \"main.go\"\r\n        ],\r\n        \"Deps\": [\r\n                \"internal/bytealg\",\r\n                \"internal/cpu\",\r\n                \"runtime\",\r\n                \"runtime/internal/atomic\",\r\n                \"runtime/internal/sys\",\r\n                \"unsafe\"\r\n        ]\r\n}\r\n```\r\n\r\nHowever, if we create the same syntax error in a test file (continuing the example above):\r\n\r\n```\r\n$ rm main.go\r\n$ cat <<EOD >main_test.go\r\npackage main\r\n\r\nfunc InTest() {\r\n        var x interface{}\r\n        x.\r\n}\r\nEOD\r\n$ go list -e -test -json .\r\n{\r\n        \"Dir\": \"/tmp/tmp.qlrtnE4Htk\",\r\n        \"ImportPath\": \"example.com/hello\",\r\n        \"Name\": \"main\",\r\n        \"Target\": \"/home/gopher/gopath/bin/hello\",\r\n        \"Module\": {\r\n                \"Path\": \"example.com/hello\",\r\n                \"Main\": true,\r\n                \"Dir\": \"/tmp/tmp.qlrtnE4Htk\",\r\n                \"GoMod\": \"/tmp/tmp.qlrtnE4Htk/go.mod\"\r\n        },\r\n        \"Match\": [\r\n                \".\"\r\n        ],\r\n        \"Deps\": [\r\n                \"internal/bytealg\",\r\n                \"internal/cpu\",\r\n                \"runtime\",\r\n                \"runtime/internal/atomic\",\r\n                \"runtime/internal/sys\",\r\n                \"unsafe\"\r\n        ],\r\n        \"TestGoFiles\": [\r\n                \"main_test.go\"\r\n        ]\r\n}\r\n{\r\n        \"ImportPath\": \"example.com/hello.test\",\r\n        \"Error\": {\r\n                \"ImportStack\": null,\r\n                \"Pos\": \"\",\r\n                \"Err\": \"\\nmain_test.go:6:1: expected selector or type assertion, found '}'\"\r\n        }\r\n}\r\n```\r\n\r\nthe test package, `example.com/hello.test`, fails to list.\r\n\r\n### What did you expect to see?\r\n\r\nGiven the successful list of the `main` package despite the syntax error, I think it makes sense for the `example.com/hello.test` test package to list successfully too.\r\n\r\n### What did you see instead?\r\n\r\nAn error in the list of `example.com/hello.test`"}}
{"actor":{"display_login":"myitcv"}}