Skip to content

Commit

Permalink
Merge pull request #648 from kralicky/origin/fix-selector-expression-…
Browse files Browse the repository at this point in the history
…panic

🐛 Fixed panic when parsing selector expressions containing composite literals
  • Loading branch information
k8s-ci-robot authored Apr 28, 2022
2 parents 8cb5ce8 + 3102f89 commit 32ad710
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
6 changes: 6 additions & 0 deletions pkg/crd/testdata/cronjob_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ type CronJobSpec struct {
// +kubebuilder:validation:XValidation:rule="self.size() % 2 == 0",message="must have even length"
// +kubebuilder:validation:XValidation:rule="true"
StringWithEvenLength string `json:"stringWithEvenLength,omitempty"`

// Checks that fixed-length arrays work
Array [3]int `json:"array,omitempty"`

// Checks that arrays work when the type contains a composite literal
ArrayUsingCompositeLiteral [len(struct{ X [3]int }{}.X)]string `json:"arrayUsingCompositeLiteral,omitempty"`
}

type ContainsNestedMap struct {
Expand Down
11 changes: 11 additions & 0 deletions pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ spec:
spec:
description: CronJobSpec defines the desired state of CronJob
properties:
array:
description: Checks that fixed-length arrays work
items:
type: integer
type: array
arrayUsingCompositeLiteral:
description: Checks that arrays work when the type contains a composite
literal
items:
type: string
type: array
associativeList:
description: This tests that associative lists work.
items:
Expand Down
11 changes: 8 additions & 3 deletions pkg/loader/refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,14 @@ func (c *referenceCollector) Visit(node ast.Node) ast.Visitor {
// local reference or dot-import, ignore
return nil
case *ast.SelectorExpr:
pkgName := typedNode.X.(*ast.Ident).Name
c.refs.external(pkgName)
return nil
switch x := typedNode.X.(type) {
case *ast.Ident:
pkgName := x.Name
c.refs.external(pkgName)
return nil
default:
return c
}
default:
return c
}
Expand Down

0 comments on commit 32ad710

Please sign in to comment.