Skip to content

go/packages: Fix loading syntax for imports when types not requested. #189

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go/packages/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 9 additions & 7 deletions go/packages/packages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down