diff --git a/CHANGELOG.md b/CHANGELOG.md index 96067e3..f4c4426 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # 1.14.4 (Unreleased) * `msgpack`: Now uses string encoding instead of float encoding for a whole number that is too large to fit in any of MessagePack's integer types. +* `function/stdlib`: Type conversion functions (constructed with `MakeToFunc`) can now convert null values of unknown type into null values of the target type, rather than returning an unknown value in that case. # 1.14.3 (February 29, 2024) diff --git a/cty/function/stdlib/conversion.go b/cty/function/stdlib/conversion.go index 5d06a45..406dea2 100644 --- a/cty/function/stdlib/conversion.go +++ b/cty/function/stdlib/conversion.go @@ -30,8 +30,9 @@ func MakeToFunc(wantTy cty.Type) function.Function { // messages to be more appropriate for an explicit type // conversion, whereas the cty function system produces // messages aimed at _implicit_ type conversions. - Type: cty.DynamicPseudoType, - AllowNull: true, + Type: cty.DynamicPseudoType, + AllowNull: true, + AllowDynamicType: true, }, }, Type: func(args []cty.Value) (cty.Type, error) { diff --git a/cty/function/stdlib/conversion_test.go b/cty/function/stdlib/conversion_test.go index c25cec7..41796c8 100644 --- a/cty/function/stdlib/conversion_test.go +++ b/cty/function/stdlib/conversion_test.go @@ -56,6 +56,12 @@ func TestTo(t *testing.T) { cty.NullVal(cty.Number), ``, }, + { + cty.NullVal(cty.DynamicPseudoType), + cty.Number, + cty.NullVal(cty.Number), + ``, + }, { cty.UnknownVal(cty.Bool), cty.String,