Skip to content
Open
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
7 changes: 6 additions & 1 deletion sjsonnet/src/sjsonnet/Val.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,18 @@ final class LazyExpr(
private var scope: ValScope,
private var ev: Evaluator)
extends Lazy {
private var evaluating: Boolean = false
def value: Val = {
if (ev == null) exprOrVal.asInstanceOf[Val]
else {
else if (evaluating) {
Error.fail("Infinite recursion detected (self-referential thunk)")
} else {
evaluating = true
val r = ev.visitExpr(exprOrVal.asInstanceOf[Expr])(scope)
exprOrVal = r // cache result
scope = null.asInstanceOf[sjsonnet.ValScope] // allow GC
ev = null // sentinel: marks as computed
evaluating = false
r
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
local x = x; x
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sjsonnet.Error: Infinite recursion detected (self-referential thunk)
at [<root>].(error.self_referential_thunk.jsonnet:1:7)
Loading