Skip to content

x/tools/go/packages: "no metadata for" error when mode contains LoadTypes without LoadImports #32814

Closed
@jayconrod

Description

@jayconrod

What version of Go are you using (go version)?

go version devel +0d4de70c1c2 Thu Jun 27 17:26:05 2019 +0000 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/jayconrod/Library/Caches/go-build"
GOENV="/Users/jayconrod/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/jayconrod/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org"
GOROOT="/Users/jayconrod/Code/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/jayconrod/Code/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/jayconrod/Code/test/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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/rq/x0692kqj6ml8cvrhcqh5bswc008xj1/T/go-build811718838=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I want to load type information for a set of packages. I tried to use this mode:

packages.NeedName | packages.NeedTypes | packages.NeedSyntax | packages.NeedTypesInfo | packages.NeedTypesSizes,

This doesn't include NeedImports or NeedDeps. I know that go/packages needs to load transitive imports (or their export data) to get type information, but I don't care if the Imports field is populated in the returned packages.

This can be reproduced with the program below using golang.org/x/tools v0.0.0-20190627185803-429858501117:

package main

import (
	"log"

	"golang.org/x/tools/go/packages"
)

func main() {
	cfg := &packages.Config{
		Mode: packages.NeedName | packages.NeedTypes | packages.NeedSyntax | packages.NeedTypesInfo | packages.NeedTypesSizes,
	}
	pkgs, err := packages.Load(cfg, "fmt")
	if err != nil {
		log.Fatal(err)
	}
	for _, pkg := range pkgs {
		for _, e := range pkg.Errors {
			log.Fatal(e)
		}
	}
}

What did you expect to see?

I get a strange error message like:

/Users/jayconrod/Code/go/src/fmt/errors.go:7:8: could not import errors (no metadata for errors)

The message changes from run to run (I think it can be any imported package).

What did you see instead?

Type information loaded successfully. Imports field nil in returned packages.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions