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

decoder: Fix collection of implied declared targets of complex types #259

Merged
merged 2 commits into from
Apr 18, 2023

Conversation

radeksimko
Copy link
Member

@radeksimko radeksimko commented Apr 14, 2023

As discovered in #251

UX Impact

There currently aren't any constraints in the Terraform schema involving targetable List/Set/Tuple/Map/Object - most occurrences are either not targetable or are implied through LiteralType or AnyExpression, or part of OneOf where AnyExpression takes precedence when collecting targets.

TL;DR there's no expected UX impact on Terraform LS users.

This was only discovered because some existing tests being updated in #251

Implementation Notes

There are situations where the schema may be vague and the user may benefit from seeing the fully inferred type, rather than just any in certain contexts. We already do that for the most obvious case of LiteralType{Type: cty.DynamicPseudoType} and AnyExpression{} equivalent.

if typ == cty.DynamicPseudoType {
val, diags := lt.expr.Value(&hcl.EvalContext{})
if !diags.HasErrors() {
typ = val.Type()
}
}

We could potentially implement InferType() for all the impacted types, but there's no immediate benefit given the above + this would require some more changes to take advantage of such type inference. We'd e.g. have to introduce TypeHint to TargetContext and get all the expression types to actually use the inferred type when collecting the targets.

The edge cases this could handle involve either explicit List, Set, Tuple, Map or Object constraints with cty.DynamicPseudoType element type, or LiteralType{Type: cty.List(cty.DynamicPseudoType)} and similar.

@radeksimko radeksimko added the bug Something isn't working label Apr 14, 2023
@radeksimko radeksimko requested a review from a team as a code owner April 14, 2023 10:31
@radeksimko radeksimko self-assigned this Apr 14, 2023
Copy link
Member

@dbanck dbanck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the approach and we can always refine it in the future if necessary.

@dbanck dbanck merged commit 43d4964 into main Apr 18, 2023
@dbanck dbanck deleted the f-complex-constraint-type branch April 18, 2023 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants