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

convert: Fix MismatchMessage for object attributes #78

Conversation

alisdair
Copy link
Contributor

When determining which object attributes cause a type mismatch, we must disregard equal attribute types. Previously we would attempt to find a conversion between them, deciding that the attribute type was a mismatch if no conversion exists. However, this is invalid if the two types are equal, because GetConversion returns nil for equal primitive types.

Because of non-deterministic map iteration order, the test case added in this commit failed approximately 2/3 of the time before the change. It now passes consistently.

Terraform issue report: hashicorp/terraform#27010

When determining which object attributes cause a type mismatch, we must
disregard equal attribute types. Previously we would attempt to find a
conversion between them, deciding that the attribute type was a mismatch
if no conversion exists. However, this is invalid if the two types are
equal, because GetConversion returns nil for equal primitive types.

Because of non-deterministic map iteration order, the test case added in
this commit failed approximately 2/3 of the time before the change. It
now passes consistently.
@codecov
Copy link

codecov bot commented Nov 23, 2020

Codecov Report

Merging #78 (0d0da20) into main (72c7e3e) will decrease coverage by 0.08%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #78      +/-   ##
==========================================
- Coverage   70.35%   70.27%   -0.09%     
==========================================
  Files          79       79              
  Lines        6548     6550       +2     
==========================================
- Hits         4607     4603       -4     
- Misses       1497     1503       +6     
  Partials      444      444              
Impacted Files Coverage Δ
cty/convert/mismatch_msg.go 71.42% <100.00%> (+0.59%) ⬆️
cty/convert/compare_types.go 92.59% <0.00%> (-7.41%) ⬇️

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 72c7e3e...0d0da20. Read the comment docs.

@apparentlymart
Copy link
Collaborator

Thanks! This makes sense to me, and indeed this (equal types returning a nil conversion) is a gotcha that's caught me out a few times now.

I remember when I first built this that there was a good reason why returning nil for equal types was important, but I don't remember now what it was. Perhaps when I have some spare time I'll try making equal types return a non-op conversion instead and see what breaks to see if it reminds me why it's designed this way. 😀

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

2 participants