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

types: Prevent panic with uninitialized Number Value #200

Merged
merged 3 commits into from
Oct 5, 2021

Conversation

bflad
Copy link
Contributor

@bflad bflad commented Oct 5, 2021

Closes #89
Reference: hashicorp/terraform-plugin-go#114

This change will ensure that if the Number Value pointer is nil, that the returned value is an untyped nil, rather than a *big.Float typed nil.

The upstream (tftypes.Value).IsNull() method can only detect untyped nil for values. A related fix for tftypes.NewValue() to convert a *big.Float nil value into an untyped nil has also been merged upstream to fix this in depth.

Previously, this new test case would pass:

		"value-nil": {
			input:       Number{Value: nil},
			expectation: (*big.Float)(nil),
		},

Now it appropriately expects:

		"value-nil": {
			input:       Number{Value: nil},
			expectation: nil,
		},

Reference: #89
Reference: hashicorp/terraform-plugin-go#114

This change will ensure that if the `Number` `Value` pointer is `nil`, that the returned value is an untyped `nil`, rather than a `*big.Float` typed `nil`.

The upstream `(tftypes.Value).IsNull()` method can only detect untyped `nil` for values. A related fix for `tftypes.NewValue()` to convert a `*big.Float` `nil` value into an untyped `nil` has also been merged upstream to fix this in depth.

Previously, this new test case would pass:

```go
		"value-nil": {
			input:       Number{Value: nil},
			expectation: (*big.Float)(nil),
		},
```

Now it appropriately expects:

```go
		"value-nil": {
			input:       Number{Value: nil},
			expectation: nil,
		},
```
@bflad bflad added bug Something isn't working types Issues and pull requests about our types abstraction and implementations. labels Oct 5, 2021
@bflad bflad requested a review from a team October 5, 2021 20:09
@bflad bflad merged commit 836a94d into main Oct 5, 2021
@bflad bflad deleted the bflad-b-Number-Value-nil branch October 5, 2021 20:20
@bflad bflad added this to the v0.5.0 milestone Oct 5, 2021
@github-actions
Copy link

github-actions bot commented Nov 5, 2021

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 Nov 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working types Issues and pull requests about our types abstraction and implementations.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panic for unset types.Number
2 participants