diff --git a/go.mod b/go.mod index b20c30e7b2..1fe2500314 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/logrusorgru/aurora/v4 v4.0.0 github.com/onflow/atree v0.10.1 github.com/onflow/crypto v0.25.3 - github.com/onflow/fixed-point v0.0.0-20250828224344-9e339b60b326 + github.com/onflow/fixed-point v0.1.0 github.com/rivo/uniseg v0.4.7 github.com/schollz/progressbar/v3 v3.18.0 github.com/stretchr/testify v1.10.0 diff --git a/go.sum b/go.sum index 0d35f28f07..488a24ede3 100644 --- a/go.sum +++ b/go.sum @@ -253,8 +253,8 @@ github.com/onflow/atree v0.10.1 h1:8sixWP3l3LitcyuKkVepbIsLbfr7JN3cCB/iA1j2JD8= github.com/onflow/atree v0.10.1/go.mod h1:+BuiL0XuIigHJqwkdIuDNzxXvyDx1jYUog/w+iZhcE8= github.com/onflow/crypto v0.25.3 h1:XQ3HtLsw8h1+pBN+NQ1JYM9mS2mVXTyg55OldaAIF7U= github.com/onflow/crypto v0.25.3/go.mod h1:+1igaXiK6Tjm9wQOBD1EGwW7bYWMUGKtwKJ/2QL/OWs= -github.com/onflow/fixed-point v0.0.0-20250828224344-9e339b60b326 h1:WgHDYQo283gJadQElJ8e6K9wiAsNL6F7npDnE1DisLA= -github.com/onflow/fixed-point v0.0.0-20250828224344-9e339b60b326/go.mod h1:gJdoHqKtToKdOZbvryJvDZfcpzC7d2fyWuo3ZmLtcGY= +github.com/onflow/fixed-point v0.1.0 h1:ez9rXM/1DbhxxyCwWX7TDpS/pla/0ynOp3R3Y3CR5+c= +github.com/onflow/fixed-point v0.1.0/go.mod h1:gJdoHqKtToKdOZbvryJvDZfcpzC7d2fyWuo3ZmLtcGY= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= diff --git a/interpreter/value_fix128.go b/interpreter/value_fix128.go index 42870b9713..b4f903a44b 100644 --- a/interpreter/value_fix128.go +++ b/interpreter/value_fix128.go @@ -629,18 +629,18 @@ func (v Fix128Value) ToBigInt() *big.Int { } func handleFixedpointError(err error, locationRange LocationRange) { - switch err { + switch err.(type) { // `fix.ErrUnderflow` happens when the value is within the range but is too small // to be represented using the current bit-length. // These should be treated as non-errors, and should return the truncated value // (assumes that the value returned is already the truncated value). - case nil, fix.ErrUnderflow: + case nil, fix.UnderflowError: return - case fix.ErrOverflow: + case fix.PositiveOverflowError: panic(&OverflowError{ LocationRange: locationRange, }) - case fix.ErrNegOverflow: + case fix.NegativeOverflowError: panic(&UnderflowError{ LocationRange: locationRange, }) @@ -653,20 +653,15 @@ func fix128SaturationArithmaticResult( result fix.Fix128, err error, ) fix.Fix128 { - if err == nil { - return result - } - // Should not panic on overflow/underflow. - - // TODO: Switch on error type, rather than the value. - // Need changes to the fixedpoint library. - switch err { - case fix.ErrOverflow: + switch err.(type) { + case nil: + return result + case fix.PositiveOverflowError: return fix.Fix128Max - case fix.ErrNegOverflow: + case fix.NegativeOverflowError: return fix.Fix128Min - case fix.ErrUnderflow: + case fix.UnderflowError: return fix.Fix128Zero default: panic(err) diff --git a/interpreter/value_ufix128.go b/interpreter/value_ufix128.go index 1e2f2b2cff..882563bbd8 100644 --- a/interpreter/value_ufix128.go +++ b/interpreter/value_ufix128.go @@ -625,20 +625,15 @@ func ufix128SaturationArithmaticResult( result fix.UFix128, err error, ) fix.UFix128 { - if err == nil { - return result - } - // Should not panic on overflow/underflow. - - // TODO: Switch on error type, rather than the value. - // Need changes to the fixedpoint library. - switch err { - case fix.ErrOverflow: + switch err.(type) { + case nil: + return result + case fix.PositiveOverflowError: return fixedpoint.UFix128TypeMax - case fix.ErrNegOverflow: + case fix.NegativeOverflowError: return fixedpoint.UFix128TypeMin - case fix.ErrUnderflow: + case fix.UnderflowError: return fix.UFix128Zero default: panic(err) diff --git a/tools/compatibility-check/go.mod b/tools/compatibility-check/go.mod index 1c98d2a404..1b9e7395e9 100644 --- a/tools/compatibility-check/go.mod +++ b/tools/compatibility-check/go.mod @@ -47,7 +47,7 @@ require ( github.com/multiformats/go-varint v0.0.7 // indirect github.com/onflow/atree v0.10.1 // indirect github.com/onflow/crypto v0.25.3 // indirect - github.com/onflow/fixed-point v0.0.0-20250828224344-9e339b60b326 // indirect + github.com/onflow/fixed-point v0.1.0 // indirect github.com/onflow/flow-core-contracts/lib/go/templates v1.3.3-0.20241017220455-79fdc6c8ba53 // indirect github.com/onflow/flow-ft/lib/go/contracts v1.0.1 // indirect github.com/onflow/flow-ft/lib/go/templates v1.0.1 // indirect diff --git a/tools/compatibility-check/go.sum b/tools/compatibility-check/go.sum index c6aadee0fe..4545cee9f7 100644 --- a/tools/compatibility-check/go.sum +++ b/tools/compatibility-check/go.sum @@ -343,8 +343,8 @@ github.com/onflow/atree v0.10.1 h1:8sixWP3l3LitcyuKkVepbIsLbfr7JN3cCB/iA1j2JD8= github.com/onflow/atree v0.10.1/go.mod h1:+BuiL0XuIigHJqwkdIuDNzxXvyDx1jYUog/w+iZhcE8= github.com/onflow/crypto v0.25.3 h1:XQ3HtLsw8h1+pBN+NQ1JYM9mS2mVXTyg55OldaAIF7U= github.com/onflow/crypto v0.25.3/go.mod h1:+1igaXiK6Tjm9wQOBD1EGwW7bYWMUGKtwKJ/2QL/OWs= -github.com/onflow/fixed-point v0.0.0-20250828224344-9e339b60b326 h1:WgHDYQo283gJadQElJ8e6K9wiAsNL6F7npDnE1DisLA= -github.com/onflow/fixed-point v0.0.0-20250828224344-9e339b60b326/go.mod h1:gJdoHqKtToKdOZbvryJvDZfcpzC7d2fyWuo3ZmLtcGY= +github.com/onflow/fixed-point v0.1.0 h1:ez9rXM/1DbhxxyCwWX7TDpS/pla/0ynOp3R3Y3CR5+c= +github.com/onflow/fixed-point v0.1.0/go.mod h1:gJdoHqKtToKdOZbvryJvDZfcpzC7d2fyWuo3ZmLtcGY= github.com/onflow/flow-core-contracts/lib/go/contracts v1.4.0 h1:R86HaOuk6vpuECZnriEUE7bw9inC2AtdSn8lL/iwQLQ= github.com/onflow/flow-core-contracts/lib/go/contracts v1.4.0/go.mod h1:9asTBnB6Tw2UlVVtQKyS/egYv3xr4zVlJnJ75z1dfac= github.com/onflow/flow-core-contracts/lib/go/templates v1.3.3-0.20241017220455-79fdc6c8ba53 h1:swCMX7k//QjHatAZ3URX4GhfUWmLc6S/tmaw2mS/0ZU=