reference: Update type matching to align w/ Terraform's #243
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Terraform itself basically doesn't use cty's TestConformance, but instead uses the convert.Convert function. This makes the type comparison a lot more lenient, where it accepts basically any primitive type for any other. It does however reject mismatch between complex types.
Other products / language servers may benefit from the stricter comparison (as implemented by
TestConformance
) but we do not have enough data to understand this problem space and so we optimise for Terraform for now. This should not hurt other products unless they have a lot of references to filter. At worst they'll get more completion items and hover/semtokens for references which are not relevant, but should still get the ones which are relevant. They may also happen to implement type comparison same way as Terraform. 🤷🏻Why now?
Because #232 is introducing support for functions and needs to decide how to compare constraints with return types, which is a similar problem to comparing references and so I believe the two places should agree on how to do this.
The alternative would be reusing the strict
TestConformance
there, which is what I first attempted, but it had some other odd edge cases, wherecty.DynamicPseudoType
[function return type] is considered mismatch forcty.String
constraint.Example
^ this is valid configuration which produces
42
(number)There is a wider conversation to have about promoting best practice by suppressing (but accepting) patterns which do not follow best practice. This could mean not providing completion for examples such as the one above, but providing hover, semantic tokens, go-to-* etc. This has two pre-requisites though:
ValidateFilePerSchema()
#57 but we'll need to make sure we fully understand the impact of precise comparisons there and the edge cases (e.g. by running a lot of existing configuration through the validation logic).