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

tftypes: Enhance Type Comparisons Functionality #94

Merged
merged 18 commits into from
Aug 10, 2021
Merged

Conversation

bflad
Copy link
Contributor

@bflad bflad commented Aug 9, 2021

Closes #80

Each type now implements three separate and distinct comparison methods:

  • (T).Equal(): performs deep type equality checks, including attribute/element types and whether attributes are optional or not.
  • (T).Is(): performs shallow type equality checks, in that the root type is compared, but underlying attribute/element types are not.
  • (T).UsableAs(): performs type conformance checks. This primarily checks if the target implements DynamicPsuedoType in a compatible manner.

paddycarver and others added 13 commits August 5, 2021 11:24
Update our Type interface to include UsableAs and Equal explicitly.

Add placeholders for UsableAs and Equal on all types, so tests can run.

Update String, Number, Bool, and DynamicPseudoType to have UsableAs
implementations, and tests for those implementations. DynamicPseudoType
will panic when UsableAs is called on it, because DynamicPseudoType is a
type constraint, it should never be associated with a Value.

This work will allow us to resolve #83.
…() into Equal() and Is()

The interface now accounts for the differing semantics of Equal() and Is(), which means the dual purpose equals() method is extraneous.
Prevent issues with DynamicPsuedoType handling.
More accurate behavior after Is() refactoring and prevents panics.
…actions so testing does not require adjustment
Leave descriptive comment for future travelers.
@bflad bflad added enhancement New feature or request breaking-change This will impact or improve our compatibility posture labels Aug 9, 2021
@bflad bflad requested review from paddycarver and kmoe August 9, 2021 19:16
Copy link
Contributor

@paddycarver paddycarver left a comment

Choose a reason for hiding this comment

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

This looks right to me. Really pleased with how this all came out, really nice work.

I was wrong, you can have null DynamicPseudoType values. :( We can take care of adding that in another PR, though. I'll open an issue.

@bflad bflad merged commit 217216e into main Aug 10, 2021
@bflad bflad deleted the f-type-comparisons branch August 10, 2021 19:06
@bflad bflad added this to the v0.4.0 milestone Aug 10, 2021
bflad added a commit that referenced this pull request Jan 7, 2022
Reference: #94
Reference: #99
Reference: #100
Reference: #128
Reference: #133

Reverts incorrect logic for handling DynamicPseudoType values in `tftypes`. This type information must be preserved when traversing the protocol, as Terraform CLI decodes values based on the schema information. If a concrete value type is used where DynamicPseudoType is expected, Terraform CLI will return errors such as (given an object of 4 attributes, when DynamicPseudoType is expected):

```
│ Error: ["manifest"]: msgpack: invalid code=84 decoding array length
```
bflad added a commit that referenced this pull request Jan 13, 2022
Reference: #94
Reference: #99
Reference: #100
Reference: #128
Reference: #133

Reverts incorrect logic for handling DynamicPseudoType values in `tftypes`. This type information must be preserved when traversing the protocol, as Terraform CLI decodes values based on the schema information. If a concrete value type is used where DynamicPseudoType is expected, Terraform CLI will return errors such as (given an object of 4 attributes, when DynamicPseudoType is expected):

```
│ Error: ["manifest"]: msgpack: invalid code=84 decoding array length
```
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
breaking-change This will impact or improve our compatibility posture enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make type comparisons clearer
2 participants