we must evaluate to DynamicVal during Validate

Because tuple types have a fixed number of elements, and we may not know
the number of expanded instances, we can't use an unknown tuple type to
validate index expressions.
This commit is contained in:
James Bardin 2020-04-23 15:17:46 -04:00
parent 7290e28ca4
commit 91e243b878
1 changed files with 10 additions and 2 deletions

View File

@ -520,7 +520,11 @@ func (d *evaluationStateData) GetModule(addr addrs.ModuleCall, rng tfdiags.Sourc
// unknown value. This will ensure the types looks correct, since we built // unknown value. This will ensure the types looks correct, since we built
// the objects based on the configuration. // the objects based on the configuration.
if d.Operation == walkValidate { if d.Operation == walkValidate {
return cty.UnknownVal(ret.Type()), diags // While we know the type here and it would be nice to validate whether
// indexes are valid or not, because tuples have a fixed number of
// elements we can't simply return an unknown tuple type since we have
// not expanded any instances during validation.
return cty.DynamicVal, diags
} }
return ret, diags return ret, diags
@ -754,7 +758,11 @@ func (d *evaluationStateData) GetResource(addr addrs.Resource, rng tfdiags.Sourc
// collected here may not correspond with configuration, so they must be // collected here may not correspond with configuration, so they must be
// unknown. // unknown.
if d.Operation == walkValidate { if d.Operation == walkValidate {
return cty.UnknownVal(ret.Type()), diags // While we know the type here and it would be nice to validate whether
// indexes are valid or not, because tuples have a fixed number of
// elements we can't simply return an unknown tuple type since we have
// not expanded any instances during validation.
return cty.DynamicVal, diags
} }
return ret, diags return ret, diags