version int // export format version
// object lists
- strList []string // in order of appearance
- pkgList []*types.Package // in order of appearance
- typList []types.Type // in order of appearance
+ strList []string // in order of appearance
+ pkgList []*types.Package // in order of appearance
+ typList []types.Type // in order of appearance
+ interfaceList []*types.Interface // for delayed completion only
trackAllTypes bool
// position encoding
// ignore compiler-specific import data
// complete interfaces
- for _, typ := range p.typList {
- // If we only record named types (!p.trackAllTypes),
- // we must check the underlying types here. If we
- // track all types, the Underlying() method call is
- // not needed.
- // TODO(gri) Remove if p.trackAllTypes is gone.
- if it, ok := typ.Underlying().(*types.Interface); ok {
- it.Complete()
- }
+ // TODO(gri) re-investigate if we still need to do this in a delayed fashion
+ for _, typ := range p.interfaceList {
+ typ.Complete()
}
// record all referenced packages as imports
}
t := types.NewInterface(p.methodList(parent), embeddeds)
+ p.interfaceList = append(p.interfaceList, t)
if p.trackAllTypes {
p.typList[n] = t
}
// This package only handles gc export data.
if runtime.Compiler != "gc" {
t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler)
- return
}
if outFn := compile(t, "testdata", "exports.go"); outFn != "" {
// This package only handles gc export data.
if runtime.Compiler != "gc" {
t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler)
- return
}
const dir = "./testdata/versions"
// This package only handles gc export data.
if runtime.Compiler != "gc" {
t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler)
- return
}
dt := maxTime
// This package only handles gc export data.
if runtime.Compiler != "gc" {
t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler)
- return
}
for _, test := range importedObjectTests {
// This package only handles gc export data.
if runtime.Compiler != "gc" {
t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler)
- return
}
- pkg, err := Import(make(map[string]*types.Package), "strings", ".")
- if err != nil {
- t.Fatal(err)
- }
+ pkg := importPkg(t, "strings")
scope := pkg.Scope()
for _, name := range scope.Names() {
// This package only handles gc export data.
if runtime.Compiler != "gc" {
t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler)
- return
}
imports := make(map[string]*types.Package)
// This package only handles gc export data.
if runtime.Compiler != "gc" {
t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler)
- return
}
// On windows, we have to set the -D option for the compiler to avoid having a drive
}
// import must succeed (test for issue at hand)
- pkg, err := Import(make(map[string]*types.Package), "./testdata/b", ".")
- if err != nil {
- t.Fatal(err)
- }
+ pkg := importPkg(t, "./testdata/b")
// make sure all indirectly imported packages have names
for _, imp := range pkg.Imports() {
// This package only handles gc export data.
if runtime.Compiler != "gc" {
t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler)
- return
}
// import go/internal/gcimporter which imports go/types partially
}
// look for go/types.Object type
- obj := goTypesPkg.Scope().Lookup("Object")
- if obj == nil {
- t.Fatal("go/types.Object not found")
- }
+ obj := lookupObj(t, goTypesPkg.Scope(), "Object")
typ, ok := obj.Type().(*types.Named)
if !ok {
t.Fatalf("go/types.Object type is %v; wanted named type", typ)
// This package only handles gc export data.
if runtime.Compiler != "gc" {
t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler)
- return
}
// On windows, we have to set the -D option for the compiler to avoid having a drive
// This package only handles gc export data.
if runtime.Compiler != "gc" {
t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler)
- return
}
// On windows, we have to set the -D option for the compiler to avoid having a drive
defer os.Remove(f)
}
- imports := make(map[string]*types.Package)
- if _, err := Import(imports, "./testdata/issue15920", "."); err != nil {
+ importPkg(t, "./testdata/issue15920")
+}
+
+func TestIssue20046(t *testing.T) {
+ skipSpecialPlatforms(t)
+
+ // This package only handles gc export data.
+ if runtime.Compiler != "gc" {
+ t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler)
+ }
+
+ // On windows, we have to set the -D option for the compiler to avoid having a drive
+ // letter and an illegal ':' in the import path - just skip it (see also issue #3483).
+ if runtime.GOOS == "windows" {
+ t.Skip("avoid dealing with relative paths/drive letters on windows")
+ }
+
+ if f := compile(t, "testdata", "issue20046.go"); f != "" {
+ defer os.Remove(f)
+ }
+
+ // "./issue20046".V.M must exist
+ pkg := importPkg(t, "./testdata/issue20046")
+ obj := lookupObj(t, pkg.Scope(), "V")
+ if m, index, indirect := types.LookupFieldOrMethod(obj.Type(), false, nil, "M"); m == nil {
+ t.Fatalf("V.M not found (index = %v, indirect = %v)", index, indirect)
+ }
+}
+
+func importPkg(t *testing.T, path string) *types.Package {
+ pkg, err := Import(make(map[string]*types.Package), path, ".")
+ if err != nil {
t.Fatal(err)
}
+ return pkg
+}
+
+func lookupObj(t *testing.T, scope *types.Scope, name string) types.Object {
+ if obj := scope.Lookup(name); obj != nil {
+ return obj
+ }
+ t.Fatalf("%s not found", name)
+ return nil
}