Skip to content
Merged
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
3 changes: 2 additions & 1 deletion sjsonnet/src/sjsonnet/Error.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class Error(msg: String, val stack: List[Error.Frame] = Nil, underlying: Option[
private def isApplyOrBuiltin(expr: Expr): Boolean = expr match {
case _: Expr.Apply | _: Expr.Apply0 | _: Expr.Apply1 | _: Expr.Apply2 | _: Expr.Apply3 |
_: Expr.ApplyBuiltin | _: Expr.ApplyBuiltin0 | _: Expr.ApplyBuiltin1 |
_: Expr.ApplyBuiltin2 | _: Expr.ApplyBuiltin3 | _: Expr.ApplyBuiltin4 =>
_: Expr.ApplyBuiltin2 | _: Expr.ApplyBuiltin3 | _: Expr.ApplyBuiltin4 | _: Expr.Comp |
_: Expr.ObjBody.ObjComp =>
true
case _ => false
}
Expand Down
2 changes: 2 additions & 0 deletions sjsonnet/src/sjsonnet/Expr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ object Expr {
final case class Comp(pos: Position, value: Expr, first: ForSpec, rest: Array[CompSpec])
extends Expr {
final override private[sjsonnet] def tag = ExprTags.Comp
override def exprErrorString: String = "array comprehension"
}
final case class ObjExtend(pos: Position, base: Expr, ext: ObjBody) extends Expr {
final override private[sjsonnet] def tag = ExprTags.ObjExtend
Expand Down Expand Up @@ -371,6 +372,7 @@ object Expr {
rest: List[CompSpec])
extends ObjBody {
final override private[sjsonnet] def tag = ExprTags.`ObjBody.ObjComp`
override def exprErrorString: String = "object comprehension"
override def toString: String =
s"ObjComp($pos, ${arrStr(preLocals)}, $key, $value, ${arrStr(postLocals)}, $first, $rest)"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
sjsonnet.Error: In comprehension, can only iterate over array, not string
at [array comprehension].(array_comp_try_iterate_over_empty_string.jsonnet:1:4)
at [<root>].(array_comp_try_iterate_over_empty_string.jsonnet:1:1)

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
sjsonnet.Error: In comprehension, can only iterate over array, not object
at [array comprehension].(array_comp_try_iterate_over_obj.jsonnet:1:4)
at [<root>].(array_comp_try_iterate_over_obj.jsonnet:1:1)

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
sjsonnet.Error: In comprehension, can only iterate over array, not string
at [array comprehension].(array_comp_try_iterate_over_string.jsonnet:1:4)
at [<root>].(array_comp_try_iterate_over_string.jsonnet:1:1)

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
sjsonnet.Error: x
at [array comprehension].(arrcomp_if6.jsonnet:1:20)
at [<root>].(arrcomp_if6.jsonnet:1:1)

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
sjsonnet.Error: Condition must be boolean, got number
at [array comprehension].(arrcomp_if7.jsonnet:1:23)
at [<root>].(arrcomp_if7.jsonnet:1:1)

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
sjsonnet.Error: Duplicate key x in evaluated object comprehension.
sjsonnet.Error: [object comprehension] Duplicate key x in evaluated object comprehension.
at [<root>].(object_comp_duplicate.jsonnet:1:1)

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
sjsonnet.Error: xxx
at [object comprehension].(object_comp_err_index.jsonnet:1:4)
at [<root>].(object_comp_err_index.jsonnet:1:1)

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
sjsonnet.Error: Field name must be string or null, not number
sjsonnet.Error: [object comprehension] Field name must be string or null, not number
at [<root>].(object_comp_int_index.jsonnet:1:1)

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
sjsonnet.Error: In comprehension, can only iterate over array, not object
at [object comprehension].(object_comp_try_iterate_over_obj.jsonnet:1:10)
at [<root>].(object_comp_try_iterate_over_obj.jsonnet:1:1)

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
sjsonnet.Error: In comprehension, can only iterate over array, not string
at [object comprehension].(object_comp_try_iterate_over_string.jsonnet:1:10)
at [<root>].(object_comp_try_iterate_over_string.jsonnet:1:1)

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
sjsonnet.Error: In comprehension, can only iterate over array, not object
at [array comprehension].(error.comprehension_spec_object.jsonnet:17:4)
at [<root>].(error.comprehension_spec_object.jsonnet:17:1)

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
sjsonnet.Error: In comprehension, can only iterate over array, not object
at [object comprehension].(error.comprehension_spec_object2.jsonnet:17:13)
at [<root>].(error.comprehension_spec_object2.jsonnet:17:1)

6 changes: 3 additions & 3 deletions sjsonnet/test/src/sjsonnet/EvaluatorTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ object EvaluatorTests extends TestSuite {
) ==> ujson.Obj("x" -> ujson.Num(3))
// Regression test for a bug in handling of non-string field names:
evalErr("{[k]: k for k in [1]}", useNewEvaluator = useNewEvaluator) ==>
"""sjsonnet.Error: Field name must be string or null, not number
"""sjsonnet.Error: [object comprehension] Field name must be string or null, not number
|at [<root>].(:1:1)""".stripMargin
// Basic function support:
eval(
Expand Down Expand Up @@ -642,7 +642,7 @@ object EvaluatorTests extends TestSuite {
"""{ [x]: x for x in ["A", "A"]}""",
useNewEvaluator = useNewEvaluator
) ==>
"""sjsonnet.Error: Duplicate key A in evaluated object comprehension.
"""sjsonnet.Error: [object comprehension] Duplicate key A in evaluated object comprehension.
|at [<root>].(:1:1)""".stripMargin
}
test("givenDuplicateFieldsInIndirectListComprehension_expectFailure") {
Expand All @@ -652,7 +652,7 @@ object EvaluatorTests extends TestSuite {
|{ [x.a]: x for x in [y, z]}""".stripMargin,
useNewEvaluator = useNewEvaluator
) ==>
"""sjsonnet.Error: Duplicate key A in evaluated object comprehension.
"""sjsonnet.Error: [object comprehension] Duplicate key A in evaluated object comprehension.
|at [<root>].(:1:7)""".stripMargin
}
test("functionEqualsNull") {
Expand Down