diff --git a/sjsonnet/src/sjsonnet/Evaluator.scala b/sjsonnet/src/sjsonnet/Evaluator.scala index bb7632df..b5dcfe07 100644 --- a/sjsonnet/src/sjsonnet/Evaluator.scala +++ b/sjsonnet/src/sjsonnet/Evaluator.scala @@ -223,8 +223,9 @@ class Evaluator( val idx = v.nameIdx if (idx < scope.length) { val binding = scope.bindings(idx) - if (binding != null) binding.value match { + if (binding != null) binding match { case n: Val.Num => n.rawDouble + case _: Val => Double.NaN case _ => Double.NaN } else Double.NaN diff --git a/sjsonnet/test/resources/new_test_suite/tryEagerEval_lazy_thunks.jsonnet b/sjsonnet/test/resources/new_test_suite/tryEagerEval_lazy_thunks.jsonnet new file mode 100644 index 00000000..1336ac49 --- /dev/null +++ b/sjsonnet/test/resources/new_test_suite/tryEagerEval_lazy_thunks.jsonnet @@ -0,0 +1,6 @@ +// Test that tryEagerEval preserves lazy semantics: unused local bindings with side effects +// should not be forced. This matches go-jsonnet and jrsonnet behavior. +std.assertEqual( + (local a = error "should not be evaluated"; local b = a + 1; if false then b else 0), + 0 +) diff --git a/sjsonnet/test/resources/new_test_suite/tryEagerEval_lazy_thunks.jsonnet.golden b/sjsonnet/test/resources/new_test_suite/tryEagerEval_lazy_thunks.jsonnet.golden new file mode 100644 index 00000000..27ba77dd --- /dev/null +++ b/sjsonnet/test/resources/new_test_suite/tryEagerEval_lazy_thunks.jsonnet.golden @@ -0,0 +1 @@ +true