diff --git a/go/packages/packages.go b/go/packages/packages.go index 050cca43a2b..12ab1e55b0c 100644 --- a/go/packages/packages.go +++ b/go/packages/packages.go @@ -713,7 +713,7 @@ func (ld *loader) loadPackage(lpkg *loaderPackage) { // which would then require that such created packages be explicitly // inserted back into the Import graph as a final step after export data loading. // The Diamond test exercises this case. - if !lpkg.needtypes { + if !lpkg.needtypes && !lpkg.needsrc { return } if !lpkg.needsrc { diff --git a/go/packages/packages_test.go b/go/packages/packages_test.go index 5d286e900cc..94bff03f13f 100644 --- a/go/packages/packages_test.go +++ b/go/packages/packages_test.go @@ -2470,13 +2470,15 @@ func testIssue35331(t *testing.T, exporter packagestest.Exporter) { if len(pkgs) != 1 { t.Fatalf("Expected 1 package, got %v", pkgs) } - pkg := pkgs[0] - if len(pkg.Errors) > 0 { - t.Fatalf("Expected no errors in package, got %v", pkg.Errors) - } - if len(pkg.Syntax) == 0 { - t.Fatalf("Expected syntax on package, got none.") - } + packages.Visit(pkgs, func(pkg *packages.Package) bool { + if len(pkg.Errors) > 0 { + t.Errorf("Expected no errors in package %q, got %v", pkg.ID, pkg.Errors) + } + if len(pkg.Syntax) == 0 && pkg.ID != "unsafe" { + t.Errorf("Expected syntax on package %q, got none.", pkg.ID) + } + return true + }, nil) } func TestLoadModeStrings(t *testing.T) {