From b581fe86a8afaf6cfc43b2fd4caacc503d8c0b02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20Jerman?= Date: Tue, 11 Oct 2022 16:06:29 +0200 Subject: [PATCH] Quick fix for workflow function result expr. eval. when arrays are used --- automation/types/expr.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/automation/types/expr.go b/automation/types/expr.go index 7eabc6e89..2f0c65815 100644 --- a/automation/types/expr.go +++ b/automation/types/expr.go @@ -190,15 +190,26 @@ func (set ExprSet) Eval(ctx context.Context, in *expr.Vars) (*expr.Vars, error) } if e.typ != nil { + + // @note handling special case for when we're dealing with arrays but in reality + // we're expecting specific types (function results). + // If we're dealing with an array but the expression doesn't want an array, + // make it want an array. + typ := e.typ + array := &expr.Array{} + if typedValue.Type() == array.Type() && typ.Type() != array.Type() { + typ = array + } + if !knownType(typedValue) { // Expression has fixed type but value does not // cast the value of evaluation to type of the expressicason - if typedValue, err = e.typ.Cast(value); err != nil { + if typedValue, err = typ.Cast(value); err != nil { return nil, err } - } else if e.typ.Type() != typedValue.Type() && e.typ.Type() != (expr.Any{}).Type() { + } else if typ.Type() != typedValue.Type() && typ.Type() != (expr.Any{}).Type() { // - if typedValue, err = e.typ.Cast(value); err != nil { + if typedValue, err = typ.Cast(value); err != nil { return nil, err } }