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

A null dynamic value is a known value when comparing equality #55

Merged
merged 6 commits into from
Jun 5, 2020
Merged

A null dynamic value is a known value when comparing equality #55

merged 6 commits into from
Jun 5, 2020

Conversation

jbardin
Copy link
Contributor

@jbardin jbardin commented May 30, 2020

When checking for nested dynamic types within complex types for equality comparison, we need to also verify that those dynamic types are not already known to be null.

Add the Value.HasWhollyKnownType method, to check for nested DynamicVal values. HasWhollyKnownType indicates not only that this value is not wholly known, but the type may change as well; as opposed to HasDynamicTypes, which only indicates that DynamicPseudoType exists within the type. This is used in the Value.Equals method before checking the type for equality.

Even when a value contains DynamicVal, we may still be able to check for inequality if the types are not conformant. Check TestConformance in both directions to see if there is any possibility of the types later becoming equal.

This also fixes a bug in Type.HasDynamicTypes, which was failing to descent into container element types.

When checking for nested dynamic types within complex types for equality
comparison, we need to also verify that those dynamic types are not
already known to be null.

Add the Value.HasDynamicValues method, to check for nested DynamicVal
values. HasDynamicValues indicates not only that this value is unknown,
but the type may change as well. This is used in the Value.Equals method
before checking the type for equality.
Even when a value contains dynamic values, we may still be able to
determine inequality when there is no way the types could conform.
Copy link
Contributor

@alisdair alisdair left a comment

Choose a reason for hiding this comment

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

FWIW this change makes perfect sense to me.

We weren't checking for unknown types within an unknown container.
HasDynamicTypes was not checking element collection types
This better describes the intent, and is a little more constant with the
other Value method names.
@codecov
Copy link

codecov bot commented Jun 5, 2020

Codecov Report

Merging #55 into master will increase coverage by 0.19%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #55      +/-   ##
==========================================
+ Coverage   70.54%   70.73%   +0.19%     
==========================================
  Files          79       79              
  Lines        7153     7176      +23     
==========================================
+ Hits         5046     5076      +30     
+ Misses       1664     1659       -5     
+ Partials      443      441       -2     
Impacted Files Coverage Δ
cty/type.go 76.31% <100.00%> (+2.63%) ⬆️
cty/value.go 58.97% <100.00%> (+20.51%) ⬆️
cty/value_ops.go 85.04% <100.00%> (+0.04%) ⬆️
cty/convert/conversion_collection.go 82.79% <0.00%> (+1.24%) ⬆️
cty/convert/mismatch_msg.go 72.81% <0.00%> (+1.94%) ⬆️
cty/element_iterator.go 95.87% <0.00%> (+2.06%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 07e6921...9bbaaee. Read the comment docs.

Copy link
Collaborator

@apparentlymart apparentlymart left a comment

Choose a reason for hiding this comment

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

This makes sense to me, though (as noted inline) I think the implementation is returning the opposite of what the new name suggests. Aside from that, this looks good to me!

// DynamicVal. This implies that both the value is not known, and the final
// type may change.
func (val Value) HasDynamicValues() bool {
func (val Value) HasWhollyKnownType() bool {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like you inverted the direction of the name here but not the implementation along with it... if I'm reading correctly, the logic below seems to produce an answer to "Doesn't have a wholly known type".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😆 oh yes, I just did a find and replace 😞 Will fix ASAP

The name was updated, but the actual logic was not inverted to match the
new name.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants