From 2e332bfcbe8e2e8f3d98017f6266a21126ea4a28 Mon Sep 17 00:00:00 2001 From: Robbie McKinstry Date: Wed, 9 Nov 2022 14:20:01 -0500 Subject: [PATCH 1/3] Guard against empty inputs for objs composed with expressions. --- pkg/codegen/pcl/invoke.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/codegen/pcl/invoke.go b/pkg/codegen/pcl/invoke.go index cb7af2d5e4ce..225391deaf44 100644 --- a/pkg/codegen/pcl/invoke.go +++ b/pkg/codegen/pcl/invoke.go @@ -150,7 +150,9 @@ func (b *binder) bindInvokeSignature(args []model.Expression) (model.StaticFunct // annotate the input args on the expression with the input type of the function if argsObject, isObjectExpression := args[1].(*model.ObjectConsExpression); isObjectExpression { - annotateObjectProperties(argsObject.Type(), fn.Inputs) + if len(argsObject.Items) > 0 && fn.Inputs != nil { + annotateObjectProperties(argsObject.Type(), fn.Inputs) + } } return sig, nil From 33a366de09c842122efe2b9f4b60038b17e1e6e5 Mon Sep 17 00:00:00 2001 From: Robbie McKinstry Date: Wed, 9 Nov 2022 14:28:15 -0500 Subject: [PATCH 2/3] Add changelog entry. --- .../20221109--pkg--panic-in-codegen-obj-expressions.yaml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelog/pending/20221109--pkg--panic-in-codegen-obj-expressions.yaml diff --git a/changelog/pending/20221109--pkg--panic-in-codegen-obj-expressions.yaml b/changelog/pending/20221109--pkg--panic-in-codegen-obj-expressions.yaml new file mode 100644 index 000000000000..777d9c80eed8 --- /dev/null +++ b/changelog/pending/20221109--pkg--panic-in-codegen-obj-expressions.yaml @@ -0,0 +1,4 @@ +changes: +- type: fix + scope: pkg + description: Fix a panic in codegen for an edge case involving object expressions without corresponding function arguments. From 2fda7def28b4969611e3b29fd0d725a706e68818 Mon Sep 17 00:00:00 2001 From: Robbie McKinstry Date: Mon, 14 Nov 2022 18:06:10 -0500 Subject: [PATCH 3/3] Relax severity of input guard. --- pkg/codegen/pcl/invoke.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/codegen/pcl/invoke.go b/pkg/codegen/pcl/invoke.go index 225391deaf44..0e0e0cd644bd 100644 --- a/pkg/codegen/pcl/invoke.go +++ b/pkg/codegen/pcl/invoke.go @@ -150,7 +150,7 @@ func (b *binder) bindInvokeSignature(args []model.Expression) (model.StaticFunct // annotate the input args on the expression with the input type of the function if argsObject, isObjectExpression := args[1].(*model.ObjectConsExpression); isObjectExpression { - if len(argsObject.Items) > 0 && fn.Inputs != nil { + if fn.Inputs != nil { annotateObjectProperties(argsObject.Type(), fn.Inputs) } }