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

Unify overflow checking in operators, field setting #448

Merged
merged 6 commits into from
Sep 18, 2021

Conversation

TristonianJones
Copy link
Collaborator

This PR consolidates additional overflow checks into overflow.go and ensures they are applied consistently when setting object field values.

There are some extensive test refactors and an update to the latest version of cel-spec v0.6.0 as well to ensure that the new code paths are being exercised and that the changes adhere to the spec. As part of this change, a small set of conformance tests now check for value truncation (rather than rounding) when converting from floating point to integer values. Given that the fixes for the incoming spec behavior were small, the truncation change was also made as part of this PR.

}

// Nanoseconds cannot overflow as time.Time normalizes them to [0, 999999999].
nsec := nsec1 - nsec2

// We need to normalize nanoseconds to be positive and carry extra nanoseconds to seconds.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note, the nanos are properly normalized in this case, so the logic ported from time.Unix was redundant and removed.

@@ -127,17 +126,17 @@ func (d Double) ConvertToNative(typeDesc reflect.Type) (interface{}, error) {
func (d Double) ConvertToType(typeVal ref.Type) ref.Val {
switch typeVal {
case IntType:
i := math.Round(float64(d))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The removal of the rounding behavior on conversion is expected and part of a cel-spec update.

common/types/overflow.go Show resolved Hide resolved
common/types/overflow.go Show resolved Hide resolved
common/types/overflow.go Outdated Show resolved Hide resolved
common/types/overflow.go Outdated Show resolved Hide resolved
@jcking jcking marked this pull request as draft September 18, 2021 00:38
@TristonianJones TristonianJones marked this pull request as ready for review September 18, 2021 00:40
@TristonianJones TristonianJones merged commit 90c32ee into google:master Sep 18, 2021
@TristonianJones TristonianJones deleted the overflow-assign-fixes branch September 18, 2021 01:49
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.

2 participants