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
15 changes: 13 additions & 2 deletions sjsonnet/src/sjsonnet/Evaluator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2149,10 +2149,16 @@ class Evaluator(
val ye = y.eval(i)
// Skip forcing when Eval references match (shared backing elements)
if (!(xe eq ye)) {
if (!equal(xe.value, ye.value)) return false
val xv = xe.value
val yv = ye.value
if (xv.isInstanceOf[Val.Func] && yv.isInstanceOf[Val.Func])
Error.fail("cannot test equality of functions")
if (!equal(xv, yv)) return false
} else if (!xe.isInstanceOf[Val]) {
// Invariant: Eval = Val | Lazy. Val is pure; Lazy may error on force.
xe.value // Force shared Lazy thunks for error semantics
val xv = xe.value // Force shared Lazy thunks for error semantics
if (xv.isInstanceOf[Val.Func])
Error.fail("cannot test equality of functions")
}
i += 1
}
Expand All @@ -2174,12 +2180,17 @@ class Evaluator(
if (!y.containsVisibleKey(k)) return false
val v1 = x.value(k, emptyMaterializeFileScopePos)
val v2 = y.value(k, emptyMaterializeFileScopePos)
if (v1.isInstanceOf[Val.Func] && v2.isInstanceOf[Val.Func])
Error.fail("cannot test equality of functions")
if (!equal(v1, v2)) return false
i += 1
}
true
case _ => false
}
case _: Val.Func =>
if (y.isInstanceOf[Val.Func]) Error.fail("cannot test equality of functions")
false
case _ => false
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
local f = function(x) x;
[
[f] == [1],
[f] != [1],
{a: f} == {a: 1},
{a: f} != {a: 1},
[1, f] == [1, 2],
[f] == [],
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
false,
true,
false,
true,
false,
false
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
local f = function(x) x;
local g = function(y) y;
[f] == [g]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sjsonnet.Error: cannot test equality of functions
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
local f = function(x) x;
local g = function(y) y;
{a: f} == {a: g}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sjsonnet.Error: cannot test equality of functions
Loading