diff --git a/core/vm.cpp b/core/vm.cpp index 667f9e1c..b90ed8d4 100644 --- a/core/vm.cpp +++ b/core/vm.cpp @@ -3246,7 +3246,8 @@ class Interpreter { case UOP_MINUS: scratch = makeNumber(-scratch.v.d); break; case UOP_BITWISE_NOT: - scratch = makeNumber(~(long)(scratch.v.d)); + scratch = makeNumber( + ~safeDoubleToInt64(scratch.v.d, ast.location)); break; default: diff --git a/test_suite/error.integer_bitwise_not.jsonnet b/test_suite/error.integer_bitwise_not.jsonnet new file mode 100644 index 00000000..b433aaf4 --- /dev/null +++ b/test_suite/error.integer_bitwise_not.jsonnet @@ -0,0 +1,3 @@ +// Value just beyond MAX_SAFE_INTEGER (2^53 - 1) +local beyond_max = 9007199254740992; // 2^53 +~beyond_max // Should throw error "numeric value outside safe integer range for bitwise operation" diff --git a/test_suite/error.integer_bitwise_not.jsonnet.golden b/test_suite/error.integer_bitwise_not.jsonnet.golden new file mode 100644 index 00000000..69b96c76 --- /dev/null +++ b/test_suite/error.integer_bitwise_not.jsonnet.golden @@ -0,0 +1,2 @@ +RUNTIME ERROR: numeric value outside safe integer range for bitwise operation. + error.integer_bitwise_not.jsonnet:3:1-12