Skip to content

Commit 32ad710

Browse files
authored
Merge pull request #648 from kralicky/origin/fix-selector-expression-panic
🐛 Fixed panic when parsing selector expressions containing composite literals
2 parents 8cb5ce8 + 3102f89 commit 32ad710

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

pkg/crd/testdata/cronjob_types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@ type CronJobSpec struct {
193193
// +kubebuilder:validation:XValidation:rule="self.size() % 2 == 0",message="must have even length"
194194
// +kubebuilder:validation:XValidation:rule="true"
195195
StringWithEvenLength string `json:"stringWithEvenLength,omitempty"`
196+
197+
// Checks that fixed-length arrays work
198+
Array [3]int `json:"array,omitempty"`
199+
200+
// Checks that arrays work when the type contains a composite literal
201+
ArrayUsingCompositeLiteral [len(struct{ X [3]int }{}.X)]string `json:"arrayUsingCompositeLiteral,omitempty"`
196202
}
197203

198204
type ContainsNestedMap struct {

pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ spec:
3535
spec:
3636
description: CronJobSpec defines the desired state of CronJob
3737
properties:
38+
array:
39+
description: Checks that fixed-length arrays work
40+
items:
41+
type: integer
42+
type: array
43+
arrayUsingCompositeLiteral:
44+
description: Checks that arrays work when the type contains a composite
45+
literal
46+
items:
47+
type: string
48+
type: array
3849
associativeList:
3950
description: This tests that associative lists work.
4051
items:

pkg/loader/refs.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,14 @@ func (c *referenceCollector) Visit(node ast.Node) ast.Visitor {
133133
// local reference or dot-import, ignore
134134
return nil
135135
case *ast.SelectorExpr:
136-
pkgName := typedNode.X.(*ast.Ident).Name
137-
c.refs.external(pkgName)
138-
return nil
136+
switch x := typedNode.X.(type) {
137+
case *ast.Ident:
138+
pkgName := x.Name
139+
c.refs.external(pkgName)
140+
return nil
141+
default:
142+
return c
143+
}
139144
default:
140145
return c
141146
}

0 commit comments

Comments
 (0)