Skip to content

Commit 73b3826

Browse files
Stop manifesting functions with no arguments in objects by default (#233)
This is inline with go-jsonnet's behavior. This behavior difference made TLA vars working properly in sjsonnet - I moved this part to the interpreter. This fixes #168
1 parent a4fee0b commit 73b3826

3 files changed

Lines changed: 9 additions & 8 deletions

File tree

sjsonnet/src/sjsonnet/Interpreter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class Interpreter(extVars: Map[String, String],
107107
override def evalDefault(expr: Expr, vs: ValScope, es: EvalScope) = {
108108
evaluator.visitExpr(expr)(if (tlaExpressions.exists(_ eq expr)) ValScope.empty else vs)
109109
}
110-
}
110+
}.apply0(f.pos)(evaluator)
111111
case x => x
112112
}
113113
} yield res

sjsonnet/src/sjsonnet/Materializer.scala

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,13 @@ abstract class Materializer {
5656
case Val.True(pos) => storePos(pos); visitor.visitTrue(-1)
5757
case Val.False(pos) => storePos(pos); visitor.visitFalse(-1)
5858
case Val.Null(pos) => storePos(pos); visitor.visitNull(-1)
59-
case f: Val.Func =>
60-
apply0(
61-
f.apply(Materializer.emptyLazyArray, null, evaluator.emptyMaterializeFileScopePos),
62-
visitor
63-
)
59+
case _: Val.Func =>
60+
Error.fail("Couldn't manifest function as JSON")
61+
case _ =>
62+
Error.fail("Unknown value type " + v.prettyName)
6463
}
6564

66-
}catch {case e: StackOverflowError =>
65+
}catch {case _: StackOverflowError =>
6766
Error.fail("Stackoverflow while materializing, possibly due to recursive value")
6867
}
6968

sjsonnet/test/src/sjsonnet/EvaluatorTests.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package sjsonnet
22

33
import utest._
4-
import TestUtils.{eval, evalErr}
4+
import TestUtils.{eval, eval0, evalErr}
55
object EvaluatorTests extends TestSuite{
66

77

@@ -30,6 +30,8 @@ object EvaluatorTests extends TestSuite{
3030
eval("local f(x) = function() true; f(42)") ==> ujson.True
3131
eval("local f(x) = function() true; f(42) == true") ==> ujson.False
3232
eval("local f(x) = function() true; f(42)() == true") ==> ujson.True
33+
assert(evalErr("{foo: function() true}").startsWith("sjsonnet.Error: Couldn't manifest function as JSON"))
34+
eval("{foo: (function() true)()}") ==> ujson.Obj{"foo" -> ujson.True}
3335
}
3436
test("members") {
3537
eval("{local x = 1, x: x}['x']") ==> ujson.Num(1)

0 commit comments

Comments
 (0)