Skip to content

Commit

Permalink
Merge pull request #209 from DirectXMan12/bug/panic-on-missing-import
Browse files Browse the repository at this point in the history
🐛 Fix panic on missing import in ref checker
  • Loading branch information
k8s-ci-robot committed May 17, 2019
2 parents 5593306 + fc2dcde commit 7092eac
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 0 additions & 1 deletion pkg/crd/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ func findKubeKinds(parser *Parser, metav1Pkg *loader.Package) []schema.GroupKind
fieldPkgPath := loader.NonVendorPath(namedField.Obj().Pkg().Path())
fieldPkg := pkg.Imports()[fieldPkgPath]
if fieldPkg != metav1Pkg {
fmt.Printf("field %q's package is %q (%v), not metav1", field.Name, namedField.Obj().Pkg().Path(), fieldPkg)
continue
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/loader/refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func mapImports(file *ast.File, importedPkgs map[string]*Package) (*importsMap,
type referenceSet struct {
file *ast.File
imports *importsMap
pkg *Package

externalRefs map[*Package]struct{}
}
Expand Down Expand Up @@ -109,6 +110,10 @@ func (r *referenceSet) collectReferences(rawType ast.Expr, filterNode NodeFilter
// external saves an external reference to the given named package.
func (r *referenceSet) external(pkgName string) {
pkg := r.imports.byName[pkgName]
if pkg == nil {
r.pkg.AddError(fmt.Errorf("use of unimported package %q", pkgName))
return
}
r.externalRefs[pkg] = struct{}{}
}

Expand Down Expand Up @@ -149,6 +154,7 @@ func allReferencedPackages(pkg *Package, filterNodes NodeFilter) []*Package {
refs := &referenceSet{
file: file,
imports: imports,
pkg: pkg,
}
refsByFile[file] = refs
}
Expand Down

0 comments on commit 7092eac

Please sign in to comment.