Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lang/funcs: type conversion functions can convert null values #30879

Merged
merged 1 commit into from Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions internal/lang/funcs/conversion.go
Expand Up @@ -30,9 +30,10 @@ 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,
AllowMarked: true,
Type: cty.DynamicPseudoType,
AllowNull: true,
AllowMarked: true,
AllowDynamicType: true,
},
},
Type: func(args []cty.Value) (cty.Type, error) {
Expand Down
10 changes: 10 additions & 0 deletions internal/lang/funcs/conversion_test.go
Expand Up @@ -33,6 +33,16 @@ func TestTo(t *testing.T) {
cty.NullVal(cty.String),
``,
},
{
// This test case represents evaluating the expression tostring(null)
// from HCL, since null in HCL is cty.NullVal(cty.DynamicPseudoType).
// The result in that case should still be null, but a null specifically
// of type string.
cty.NullVal(cty.DynamicPseudoType),
cty.String,
cty.NullVal(cty.String),
``,
},
{
cty.StringVal("a").Mark("boop"),
cty.String,
Expand Down