diff --git a/pkg/expr/expr_types.go b/pkg/expr/expr_types.go index fae386412..3ebaf9618 100644 --- a/pkg/expr/expr_types.go +++ b/pkg/expr/expr_types.go @@ -203,7 +203,7 @@ func (t *Unresolved) Assign(interface{}) (err error) { } func CastToAny(val interface{}) (interface{}, error) { - return val, nil + return UntypedValue(val), nil } func CastToArray(val interface{}) (out []TypedValue, err error) { diff --git a/pkg/expr/vars_test.go b/pkg/expr/vars_test.go index 93c5ee7be..fd050e4f2 100644 --- a/pkg/expr/vars_test.go +++ b/pkg/expr/vars_test.go @@ -2,8 +2,9 @@ package expr import ( "encoding/json" - "github.com/stretchr/testify/require" "testing" + + "github.com/stretchr/testify/require" ) // extract typed-value @@ -282,6 +283,19 @@ func TestVars_Omit(t *testing.T) { req.Equal(expected, out) } +func TestVarsTypeResolving(t *testing.T) { + var ( + req = require.New(t) + v = &Vars{} + ) + + req.NoError(v.Set("unr", &Unresolved{value: "wrapped any", typ: "Any"})) + req.NoError(v.Set("any", &Any{value: "raw any"})) + req.NoError(v.ResolveTypes(func(typ string) Type { return Any{} })) + req.Equal("wrapped any", v.value["unr"].Get()) + req.Equal("raw any", v.value["any"].Get()) +} + func TestVars_UnmarshalJSON(t *testing.T) { cases := []struct { name string