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

reflect: Use float64 string representation for float32 reflection equivalency #1015

Merged
merged 2 commits into from
Jul 2, 2024

Conversation

SBGoods
Copy link
Contributor

@SBGoods SBGoods commented Jul 1, 2024

Relates: #1014

This fixes a bug encountered when using function.Float32Parameter in a provider defined function, similar to issue #914:

=== RUN   TestFloat32Function_known
    float32_function_test.go:20: Step 1/1 error: Error running pre-apply plan: exit status 1
        
        Error: Error in function call
        
          on terraform_plugin_test.tf line 13, in output "test":
          13: 					value = provider::framework::float32(1.23)
            ├────────────────
            │ while calling provider::framework::float32(float32_param)
        
        Call to function "provider::framework::float32" failed: Value Conversion
        Error: An unexpected error was encountered trying to convert to number. This
        is always an error in the provider. Please report the following to the
        provider developer:
        
        cannot store 1.23 in float32.
--- FAIL: TestFloat32Function_known (0.36s)

The current reflection logic for float32 compares the reflection target's string representation of the float32 value with the string representation of that same value in a new big.Float object and throws an error if the representations differ. Creating a new big.Float object requires a conversion from float32 to float64 resulting in precision loss and differing string representations.

This PR switches the string comparisons to float64 and adds overflow and underflow checks for float32.

@SBGoods SBGoods requested a review from a team as a code owner July 1, 2024 19:50
@SBGoods SBGoods added this to the v1.10.0 milestone Jul 1, 2024
@SBGoods SBGoods added the bug Something isn't working label Jul 1, 2024
Copy link
Member

@austinvalle austinvalle left a comment

Choose a reason for hiding this comment

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

lgtm, nice test additions 🚀

@SBGoods SBGoods merged commit 6ab653a into main Jul 2, 2024
29 checks passed
@SBGoods SBGoods deleted the SBGoods/float32-reflection branch July 2, 2024 15:30
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants