Skip to content

Commit

Permalink
Fix error message for too many arguments whith at least one named arg
Browse files Browse the repository at this point in the history
  • Loading branch information
edgar-db committed Nov 6, 2020
1 parent 5ccdb4c commit a92d8ed
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ output/
.DS_STORE
.idea_modules
.idea
.metals
out/
2 changes: 1 addition & 1 deletion sjsonnet/src/sjsonnet/Val.scala
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ object Val{
Error.failIfNonEmpty(
repeats,
outerOffset,
(plural, names) => s"Function parameter$plural $names passed more than once"
(plural, names) => s"binding parameter a second time: $names"
)

Error.failIfNonEmpty(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
local foo (x) = x;
foo(1, x = "bar")
30 changes: 8 additions & 22 deletions sjsonnet/test/src-jvm/sjsonnet/ErrorTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -139,20 +139,14 @@ object ErrorTests extends TestSuite{
)

test("function_duplicate_arg") - check(
"""sjsonnet.Error: Function parameter x passed more than once
"""sjsonnet.Error: binding parameter a second time: x
| at .(sjsonnet/test/resources/test_suite/error.function_duplicate_arg.jsonnet:17:21)
| at .(sjsonnet/test/resources/test_suite/error.function_duplicate_arg.jsonnet:17:21)
|""".stripMargin
)
test("function_duplicate_param") - check(
"""Parse error: Expected no duplicate parameter: x:17:14, found ") x\n"""".stripMargin
)
// test("function_infinite_default") - check(
// """sjsonnet.Error: Parameter passed more than once: x
// | at .(sjsonnet/test/resources/test_suite/error.function_duplicate_arg.jsonnet:17:2)
// | at .(sjsonnet/test/resources/test_suite/error.function_duplicate_arg.jsonnet:17:21)
// |""".stripMargin
// )
test("function_too_many_args") - check(
"""sjsonnet.Error: Too many args, function has 2 parameter(s)
| at .(sjsonnet/test/resources/test_suite/error.function_too_many_args.jsonnet:19:4)
Expand Down Expand Up @@ -288,20 +282,12 @@ object ErrorTests extends TestSuite{
| at .(sjsonnet/test/resources/imports/error.too_many_arg.jsonnet:3:6)
|""".stripMargin
)
// test("overflow") - check(
// """sjsonnet.Error: my error message
// | at .(sjsonnet/test/resources/test_suite/error.invariant.simple3.jsonnet:18:10)
// |""".stripMargin
// )
// test("overflow2") - check(
// """sjsonnet.Error: my error message
// | at .(sjsonnet/test/resources/test_suite/error.invariant.simple3.jsonnet:18:10)
// |""".stripMargin
// )
// test("overflow3") - check(
// """sjsonnet.Error: my error message
// | at .(sjsonnet/test/resources/test_suite/error.invariant.simple3.jsonnet:18:10)
// |""".stripMargin
// )

test("too_many_arg_with_named_arg") - checkImports(
"""|sjsonnet.Error: binding parameter a second time: x
| at .(sjsonnet/test/resources/imports/error.too_many_arg_with_named_arg.jsonnet:2:4)
| at .(sjsonnet/test/resources/imports/error.too_many_arg_with_named_arg.jsonnet:2:4)
|""".stripMargin
)
}
}
7 changes: 6 additions & 1 deletion sjsonnet/test/src/sjsonnet/EvaluatorTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,17 @@ object EvaluatorTests extends TestSuite{
| welcome: 'Hello ' + name + '!',
|};
|{
| person2: Person('Bob', hello=123),
| person2: Person(hello=123),
|}
""".stripMargin
)
}

/*
* Wrong number of params error takes precedence on invalid param
* For that reason, to assert for invalid param we need to pass the
* right number of params in the first place.
*/
assert(ex.getMessage.contains("Function has no parameter hello"))
}

Expand Down

0 comments on commit a92d8ed

Please sign in to comment.