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

Support map(any) in config/output types #12619

Merged
merged 1 commit into from Apr 7, 2023
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
@@ -0,0 +1,4 @@
changes:
- type: fix
scope: programgen
description: Suppport the `any` type in config and outputs.
1 change: 1 addition & 0 deletions pkg/codegen/hcl2/model/type_scope.go
Expand Up @@ -6,6 +6,7 @@ import (
)

var typeBuiltins = map[string]Type{
"any": DynamicType,
"string": StringType,
"number": NumberType,
"int": IntType,
Expand Down
15 changes: 15 additions & 0 deletions pkg/codegen/pcl/binder_test.go
Expand Up @@ -267,3 +267,18 @@ func TestConfigNodeTypedIntMap(t *testing.T) {
assert.True(t, ok, "the type of config is a map type")
assert.Equal(t, mapType.ElementType, model.IntType, "the element type is an int")
}

func TestConfigNodeTypedAnyMap(t *testing.T) {
t.Parallel()
source := "config names \"map(any)\" { }"
program, diags := parseAndBindProgram(t, source, "config.pp")
contract.Ignore(diags)
assert.NotNil(t, program, "failed to parse and bind program")
assert.Equal(t, len(program.Nodes), 1, "there is one node")
config, ok := program.Nodes[0].(*pcl.ConfigVariable)
assert.True(t, ok, "first node is a config variable")
assert.Equal(t, config.Name(), "names")
mapType, ok := config.Type().(*model.MapType)
assert.True(t, ok, "the type of config is a map type")
assert.Equal(t, mapType.ElementType, model.DynamicType, "the element type is a dynamic")
}