Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions sjsonnet/src/sjsonnet/Evaluator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -712,29 +712,29 @@ class Evaluator(
(op: @switch) match {
case Expr.BinaryOp.OP_+ =>
val r = ld + rd
if (r.isNaN) Error.fail("not a number", pos)
if (r.isInfinite) Error.fail("overflow", pos)
if (r.isNaN) Error.fail("Not a number", pos)
if (r.isInfinite) Error.fail("Overflow", pos)
Val.cachedNum(pos, r)
case Expr.BinaryOp.OP_- =>
val r = ld - rd
if (r.isNaN) Error.fail("not a number", pos)
if (r.isInfinite) Error.fail("overflow", pos)
if (r.isNaN) Error.fail("Not a number", pos)
if (r.isInfinite) Error.fail("Overflow", pos)
Val.cachedNum(pos, r)
case Expr.BinaryOp.OP_* =>
val r = ld * rd
if (r.isNaN) Error.fail("not a number", pos)
if (r.isInfinite) Error.fail("overflow", pos)
if (r.isNaN) Error.fail("Not a number", pos)
if (r.isInfinite) Error.fail("Overflow", pos)
Val.cachedNum(pos, r)
case Expr.BinaryOp.OP_/ =>
if (rd == 0) Error.fail("Division by zero.", pos)
val r = ld / rd
if (r.isNaN) Error.fail("not a number", pos)
if (r.isInfinite) Error.fail("overflow", pos)
if (r.isNaN) Error.fail("Not a number", pos)
if (r.isInfinite) Error.fail("Overflow", pos)
Val.cachedNum(pos, r)
case Expr.BinaryOp.OP_% =>
if (rd == 0) Error.fail("Division by zero.", pos)
val r = ld % rd
if (r.isNaN) Error.fail("not a number", pos)
if (r.isNaN) Error.fail("Not a number", pos)
Val.cachedNum(pos, r)
// Use position-free static singletons for boolean results — this method is only called
// from comprehension fast paths where position info on boolean results is unnecessary.
Expand Down Expand Up @@ -871,29 +871,29 @@ class Evaluator(
(e.op: @switch) match {
case Expr.BinaryOp.OP_* =>
val r = visitExprAsDouble(e.lhs) * visitExprAsDouble(e.rhs)
if (r.isNaN) Error.fail("not a number", pos)
if (r.isInfinite) Error.fail("overflow", pos); r
if (r.isNaN) Error.fail("Not a number", pos)
if (r.isInfinite) Error.fail("Overflow", pos); r
case Expr.BinaryOp.OP_/ =>
val l = visitExprAsDouble(e.lhs)
val r = visitExprAsDouble(e.rhs)
if (r == 0) Error.fail("Division by zero.", pos)
val result = l / r
if (result.isNaN) Error.fail("not a number", pos)
if (result.isInfinite) Error.fail("overflow", pos); result
if (result.isNaN) Error.fail("Not a number", pos)
if (result.isInfinite) Error.fail("Overflow", pos); result
case Expr.BinaryOp.OP_% =>
val l = visitExprAsDouble(e.lhs)
val r = visitExprAsDouble(e.rhs)
if (r == 0) Error.fail("Division by zero.", pos)
val result = l % r
if (result.isNaN) Error.fail("not a number", pos); result
if (result.isNaN) Error.fail("Not a number", pos); result
case Expr.BinaryOp.OP_+ =>
val r = visitExprAsDouble(e.lhs) + visitExprAsDouble(e.rhs)
if (r.isNaN) Error.fail("not a number", pos)
if (r.isInfinite) Error.fail("overflow", pos); r
if (r.isNaN) Error.fail("Not a number", pos)
if (r.isInfinite) Error.fail("Overflow", pos); r
case Expr.BinaryOp.OP_- =>
val r = visitExprAsDouble(e.lhs) - visitExprAsDouble(e.rhs)
if (r.isNaN) Error.fail("not a number", pos)
if (r.isInfinite) Error.fail("overflow", pos); r
if (r.isNaN) Error.fail("Not a number", pos)
if (r.isInfinite) Error.fail("Overflow", pos); r
case Expr.BinaryOp.OP_<< =>
val ll = visitExprAsDouble(e.lhs).toSafeLong(pos)
val rr = visitExprAsDouble(e.rhs).toSafeLong(pos)
Expand Down Expand Up @@ -1353,21 +1353,21 @@ class Evaluator(
// Pure numeric fast path: avoid intermediate Val.Num allocation
case Expr.BinaryOp.OP_* =>
val r = visitExprAsDouble(e.lhs) * visitExprAsDouble(e.rhs)
if (r.isNaN) Error.fail("not a number", pos)
if (r.isInfinite) Error.fail("overflow", pos)
if (r.isNaN) Error.fail("Not a number", pos)
if (r.isInfinite) Error.fail("Overflow", pos)
Val.cachedNum(pos, r)
case Expr.BinaryOp.OP_- =>
val r = visitExprAsDouble(e.lhs) - visitExprAsDouble(e.rhs)
if (r.isNaN) Error.fail("not a number", pos)
if (r.isInfinite) Error.fail("overflow", pos)
if (r.isNaN) Error.fail("Not a number", pos)
if (r.isInfinite) Error.fail("Overflow", pos)
Val.cachedNum(pos, r)
case Expr.BinaryOp.OP_/ =>
val l = visitExprAsDouble(e.lhs)
val r = visitExprAsDouble(e.rhs)
if (r == 0) Error.fail("Division by zero.", pos)
val result = l / r
if (result.isNaN) Error.fail("not a number", pos)
if (result.isInfinite) Error.fail("overflow", pos)
if (result.isNaN) Error.fail("Not a number", pos)
if (result.isInfinite) Error.fail("Overflow", pos)
Val.cachedNum(pos, result)
// Polymorphic ops: nested match avoids Tuple2 allocation; Num checked first (most common)
case Expr.BinaryOp.OP_% =>
Expand All @@ -1379,7 +1379,7 @@ class Evaluator(
case Val.Num(_, rd) =>
if (rd == 0) Error.fail("Division by zero.", pos)
val result = ld % rd
if (result.isNaN) Error.fail("not a number", pos)
if (result.isNaN) Error.fail("Not a number", pos)
Val.cachedNum(pos, result)
case _ => failBinOp(l, e.op, r, pos)
}
Expand All @@ -1393,8 +1393,8 @@ class Evaluator(
(l, r) match {
case (Val.Num(_, l), Val.Num(_, r)) =>
val result = l + r
if (result.isNaN) Error.fail("not a number", pos)
if (result.isInfinite) Error.fail("overflow", pos)
if (result.isNaN) Error.fail("Not a number", pos)
if (result.isInfinite) Error.fail("Overflow", pos)
Val.cachedNum(pos, result)
case (l: Val.Str, r: Val.Str) => Val.Str.concat(pos, l, r)
case (n: Val.Num, r: Val.Str) =>
Expand Down
4 changes: 2 additions & 2 deletions sjsonnet/src/sjsonnet/Val.scala
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ object Val {
}
final case class Num(var pos: Position, private val num: Double) extends Literal {
if (num.isInfinite) {
Error.fail("overflow")
Error.fail("Overflow")
}

def prettyName = "number"
Expand Down Expand Up @@ -510,7 +510,7 @@ object Val {

override def asDouble: Double = {
if (num.isNaN) {
Error.fail("not a number")
Error.fail("Not a number")
}
num
}
Expand Down
2 changes: 1 addition & 1 deletion sjsonnet/src/sjsonnet/stdlib/ArrayModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ object ArrayModule extends AbstractFunctionModule {
*/
builtin("avg", "arr") { (_, _, arr: Val.Arr) =>
if (arr.length == 0) {
Error.fail("Cannot calculate average of an empty array")
Error.fail("Cannot calculate average of an empty array.")
}
arr match {
case r: Val.RangeArr =>
Expand Down
6 changes: 3 additions & 3 deletions sjsonnet/src/sjsonnet/stdlib/MathModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ object MathModule extends AbstractFunctionModule {
*/
builtin("pow", "x", "n") { (pos, ev, x: Double, n: Double) =>
val r = math.pow(x, n)
if (java.lang.Double.isNaN(r)) Error.fail("not a number", pos)(ev)
if (java.lang.Double.isNaN(r)) Error.fail("Not a number", pos)(ev)
r
},
/**
Expand Down Expand Up @@ -427,7 +427,7 @@ object MathModule extends AbstractFunctionModule {
*/
builtin("asin", "x") { (pos, ev, x: Double) =>
val r = math.asin(x)
if (java.lang.Double.isNaN(r)) Error.fail("not a number", pos)(ev)
if (java.lang.Double.isNaN(r)) Error.fail("Not a number", pos)(ev)
r
},
/**
Expand All @@ -439,7 +439,7 @@ object MathModule extends AbstractFunctionModule {
*/
builtin("acos", "x") { (pos, ev, x: Double) =>
val r = math.acos(x)
if (java.lang.Double.isNaN(r)) Error.fail("not a number", pos)(ev)
if (java.lang.Double.isNaN(r)) Error.fail("Not a number", pos)(ev)
r
},
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
sjsonnet.Error: [std.exp] overflow
sjsonnet.Error: [std.exp] Overflow
at [<root>].(builtin_exp3.jsonnet:1:8)

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
sjsonnet.Error: [std.exp] overflow
sjsonnet.Error: [std.exp] Overflow
at [<root>].(builtin_exp5.jsonnet:1:8)

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
sjsonnet.Error: [std.log] overflow
sjsonnet.Error: [std.log] Overflow
at [<root>].(builtin_log5.jsonnet:1:8)

2 changes: 1 addition & 1 deletion sjsonnet/test/resources/go_test_suite/div4.jsonnet.golden
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
sjsonnet.Error: overflow
sjsonnet.Error: Overflow
at [<root>].(div4.jsonnet:1:11)

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
sjsonnet.Error: overflow
sjsonnet.Error: Overflow
at [<root>].(inf_min_number.jsonnet:1:8)

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
sjsonnet.Error: overflow
sjsonnet.Error: Overflow
at [<root>].(inf_mul_number.jsonnet:1:7)

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
sjsonnet.Error: overflow
sjsonnet.Error: Overflow
at [<root>].(inf_sum_number.jsonnet:1:7)

3 changes: 2 additions & 1 deletion sjsonnet/test/resources/go_test_suite/pow4.jsonnet.golden
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
sjsonnet.Error: [std.pow] not a number
sjsonnet.Error: [std.pow] Not a number
at [<root>].(pow4.jsonnet:1:8)

2 changes: 1 addition & 1 deletion sjsonnet/test/resources/go_test_suite/pow7.jsonnet.golden
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
sjsonnet.Error: [std.pow] overflow
sjsonnet.Error: [std.pow] Overflow
at [<root>].(pow7.jsonnet:2:8)

Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sjsonnet.Error: overflow
sjsonnet.Error: Overflow
at [<root>].(error.arithmetic_overflow_addition.jsonnet:2:7)
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sjsonnet.Error: overflow
sjsonnet.Error: Overflow
at [<root>].(error.arithmetic_overflow_multiplication.jsonnet:2:7)
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sjsonnet.Error: overflow
sjsonnet.Error: Overflow
at [<root>].(error.arithmetic_overflow_subtraction.jsonnet:2:8)
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
sjsonnet.Error: [std.acos] not a number
sjsonnet.Error: [std.acos] Not a number
at [<root>].(error.math_acos_nan.jsonnet:2:9)

Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
sjsonnet.Error: [std.asin] not a number
sjsonnet.Error: [std.asin] Not a number
at [<root>].(error.math_asin_nan.jsonnet:2:9)

Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
sjsonnet.Error: [std.pow] not a number
sjsonnet.Error: [std.pow] Not a number
at [<root>].(error.math_pow_nan.jsonnet:2:8)

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
sjsonnet.Error: overflow
sjsonnet.Error: Overflow
at [<root>].(error.overflow2.jsonnet:17:7)

4 changes: 2 additions & 2 deletions sjsonnet/test/src/sjsonnet/StdMathTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ object StdMathTests extends TestSuite {
val errLog10 = evalErr("std.log10(-1)")
assert(errLog10.contains("Not a number"))
val errLog0 = evalErr("std.log(0)")
assert(errLog0.contains("overflow"))
assert(errLog0.contains("Overflow"))
val errLog2Zero = evalErr("std.log2(0)")
assert(errLog2Zero.contains("overflow"))
assert(errLog2Zero.contains("Overflow"))
// log(positive) must still work
eval("std.log(1)") ==> ujson.Num(0.0)
eval("std.log2(1)") ==> ujson.Num(0.0)
Expand Down
2 changes: 1 addition & 1 deletion sjsonnet/test/src/sjsonnet/TailCallOptimizationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object TailCallOptimizationTests extends TestSuite {
|factorial(1000)
|""".stripMargin
)
assert(err.contains("overflow"))
assert(err.contains("Overflow"))
}

test("tailstrictDeepRecursionSum") {
Expand Down
Loading