fix: error when comparing arrays containing function elements#958
Open
He-Pin wants to merge 1 commit into
Open
fix: error when comparing arrays containing function elements#958He-Pin wants to merge 1 commit into
He-Pin wants to merge 1 commit into
Conversation
425bca0 to
d819081
Compare
d819081 to
363d981
Compare
Contributor
Author
|
@stephenamar-db This is ready too. |
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 - 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 for Val.Func before skipping - Fix Scala 3.3.7 compile error from discarded non-Unit value Result: [f, 1] == [f, 1] now correctly errors with "cannot test equality of functions", matching go-jsonnet, jsonnet-cpp, and jrsonnet behavior. | Expression | go-jsonnet v0.22.0 | jsonnet-cpp v0.22.0 | jrsonnet v0.5.0-pre99 | sjsonnet (before) | sjsonnet (after) | |---|---|---|---|---|---| | f == f | ERROR | ERROR | ERROR | ERROR | ERROR | | [f, 1] == [f, 1] | ERROR | ERROR | ERROR | true (bug) | ERROR | | f == 42 | false | false | false | false | false | | [1,2,3] == [1,2,3] | true | true | true | true | true |
e523442 to
d9f67f3
Compare
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.
Summary
Fix array equality silently returning
truewhen comparing arrays containing function elements.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.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 functionsEvalreferences now force the value and check forVal.Funcbefore skippingResult
[f, 1] == [f, 1]andf == fnow correctly error with "cannot test equality of functions", matching go-jsonnet, jsonnet-cpp, and jrsonnet behavior.Behavior Comparison
local f = function(x) x; f == flocal f = function(x) x; [f, 1] == [f, 1]true(bug)local f = function(x) x; f == 42falsefalsefalsefalsefalse[1, 2, 3] == [1, 2, 3]truetruetruetruetrueReferences