Skip to content

Commit

Permalink
ext/typeexpr: Avoid refinements on dynamic values
Browse files Browse the repository at this point in the history
  • Loading branch information
wata727 authored and apparentlymart committed Aug 30, 2023
1 parent a9f8d65 commit ed6d4bf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ext/typeexpr/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (d *Defaults) apply(v cty.Value) cty.Value {
}
values[key] = defaultValue
}
if defaultRng := defaultValue.Range(); defaultRng.DefinitelyNotNull() {
if defaultRng := defaultValue.Range(); defaultRng.DefinitelyNotNull() && values[key].Type() != cty.DynamicPseudoType {
values[key] = values[key].RefineNotNull()
}
}
Expand Down
17 changes: 17 additions & 0 deletions ext/typeexpr/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,23 @@ func TestDefaults_Apply(t *testing.T) {
"foo": cty.UnknownVal(cty.String).RefineNotNull(),
}),
},
"optional attribute with dynamic value can be null": {
defaults: &Defaults{
Type: cty.ObjectWithOptionalAttrs(map[string]cty.Type{
"foo": cty.String,
}, []string{"foo"}),
DefaultValues: map[string]cty.Value{
"foo": cty.StringVal("bar"), // Important: default is non-null
},
},
value: cty.ObjectVal(map[string]cty.Value{
"foo": cty.DynamicVal,
}),
want: cty.ObjectVal(map[string]cty.Value{
// The default value is itself non-null, but dynamic value cannot be refined.
"foo": cty.DynamicVal,
}),
},
}

for name, tc := range testCases {
Expand Down

0 comments on commit ed6d4bf

Please sign in to comment.