fix: error when comparing arrays containing function elements#958
Merged
stephenamar-db merged 3 commits intoJun 18, 2026
Merged
Conversation
425bca0 to
d819081
Compare
d819081 to
363d981
Compare
Contributor
Author
|
@stephenamar-db This is ready too. |
e523442 to
d9f67f3
Compare
Motivation: go-jsonnet errors with "cannot test equality of functions" when comparing arrays that contain function elements (e.g. [f, 1] == [f, 1]). sjsonnet silently returned true because the shared-reference optimization in the array equality loop skipped forcing lazy thunks without checking if the resolved value was a function. Modification: - Guard the (x eq y) shortcut in equal() to exclude Val.Func, so same- reference functions fall through to the explicit Func case that errors - Add a Val.Func case in equal() that errors when both sides are functions - In the array equality loop, force shared Eval references and check if the resolved value is a Val.Func before skipping Result: [f, 1] == [f, 1] now correctly errors with "cannot test equality of functions", matching go-jsonnet behavior. Non-function array comparisons are unaffected.
Motivation: Scala 3.3.7 strict mode rejects discarded non-Unit values. The else branch in the array equality loop referenced `v` (a Val) without using it, causing a compilation error in native/js/wasm builds. Modification: Replace the pointless `v` reference with a comment clarifying that shared non-Func values are implicitly equal. Result: All Scala 3.3.7 targets (jvm, native, js, wasm) compile successfully.
d9f67f3 to
dbac5b8
Compare
Add test coverage for function equality comparisons inside arrays and
objects: [f] == [g] and {a: f} == {a: g} raise errors, while mixed
containers (function vs non-function) correctly return false.
4 tasks
stephenamar-db
approved these changes
Jun 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Array equality silently returned
truewhen comparing arrays containing function elements that shared the same scope binding reference. The(x eq y)reference-equality shortcut and the array equality loop's shared-reference optimization bypassed the "cannot test equality of functions" error that go-jsonnet raises. Additionally,equal()had no top-level check forVal.Funcoperands, so function comparisons in any context silently returnedfalseinstead of raising an error.Modification
(x eq y)shortcut inequal()to excludeVal.Func, so same-reference functions fall through to an explicitVal.Funccase that errorsVal.Funccase inequal()that errors when both sides are functions, returns false for func-vs-non-funcEvalreferences now force the value and check forVal.Funcbefore skippingThe top-level
Val.Funccase inequal()handles function detection at any nesting depth through recursion — no explicit checks needed in array/object comparison loops.Result
[f, 1] == [f, 1]andf == fnow correctly error with "cannot test equality of functions", matching go-jsonnet, jsonnet-cpp, and jrsonnet behavior. All nested cases ([f] == [g],{a: f} == {a: g},[[f]] == [[g]]) also work correctly throughequal()recursion.local f = function(x) x; f == flocal f = function(x) x; [f, 1] == [f, 1]true(bug)local f = function() 3; local g = function() 4; [f] == [g]false(bug)local f = function() 3; local g = function() 4; {a: f} == {a: g}false(bug)local f = function(x) x; f == 42falsefalsefalse[1, 2, 3] == [1, 2, 3]truetruetrue[f] == [1]falsefalsefalse{a: f} == {a: 1}falsefalsefalseReferences