-
Notifications
You must be signed in to change notification settings - Fork 70
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
Fix set function unification #52
Fix set function unification #52
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks for digging into this! I have a little inline comment about naming, but functionality-wise this looks great.
cty/set/rules.go
Outdated
// Equals returns true if the instance is equal to another Rules instance. | ||
// This method is necessary because some implementations may be backed by | ||
// structs which cannot be compared with ==. | ||
Equals(Rules) bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Equals
is consistent with how a method like this is named elsewhere, but it feels a little confusing in this case because it's alongside Equivalent
which is about comparing potential values, rather than the rules object itself.
What do you think about naming this SameRules
instead, just to make it a bit clearer that we're talking about comparing the rules object itself? 🤔
97deeba
to
3ec38f1
Compare
Previously, we checked if two sets had the same rules using a simple equality check. This panics if the sets contain object types, as they cannot be compared using `==`. Adding a SameRules method to the Rules interface allows us to delegate to the Type.Equals method where necessary, fixing this problem.
If one or more arguments to the stdlib set functions was an empty set of dynamic pseudo type, the functions would panic due to incompatible set rules. We can special case empty dynamic pseudo type sets to be ignored through type unification, because they are always capable of being converted to any other type.
3ec38f1
to
ac84a5d
Compare
Codecov Report
@@ Coverage Diff @@
## master #52 +/- ##
==========================================
+ Coverage 70.48% 70.53% +0.05%
==========================================
Files 79 79
Lines 7138 7151 +13
==========================================
+ Hits 5031 5044 +13
Misses 1664 1664
Partials 443 443
Continue to review full report at Codecov.
|
I did the change to rename |
Thanks, that rename makes sense to me! |
Two changes here to fix panics when using the
stdlib
set functions (setintersect
,setunion
, etc) where one of the parameters is an empty collection.Add Equals method to set.Rules
Previously, we checked if two sets had the same rules using a simple equality check. This panics if the sets contain object types, as they cannot be compared using
==
.Adding an
Equals
method to theRules
interface allows us to delegate to theType.Equals
method where necessary, fixing this problem.Fix set function crashes with empty sets
If one or more arguments to the
stdlib
set functions was an empty set of dynamic pseudo type, the functions would panic due to incompatible set rules.We can special case empty dynamic pseudo type sets to be ignored through type unification, because they are always capable of being converted to any other type.
Downstream crash
This PR fixes this Terraform crash: