Commit c7b60b3
committed
fix: reject duplicate function parameters with correct error in all contexts
Motivation:
go-jsonnet issue #873 reports that (function(x, x, x) x)(null, 3, 2)
silently returns 2 instead of rejecting duplicate parameter names.
sjsonnet already rejected duplicates in function expressions, but the
error message was misleading in local bindings and object methods.
Modification:
The params parser correctly detects duplicates via flatMapX + Fail.
However, in bind (local f(x,x)=...) and field ({f(x,x):...}), the
optional group .? around params swallowed the "no duplicate parameter"
error and backtracked, producing misleading errors like "Expected )".
Replaced .? with ./ (committed-or): "(" ~/ params ~ ")" ./ | Pass(null).
The cut ~/ after "(" commits to the params path, and ./ prevents the |
alternative from trying the fallback when the committed path fails.
Result:
All duplicate parameter contexts now produce the correct error:
"Expected no duplicate parameter: x" with accurate position info.
- (function(x, x, x) x) -> ParseError (already worked)
- local f(x, x) = x -> ParseError (was "Expected )")
- { f(x, x): x } -> ParseError (was "Expected :")
- { local f(x, x) = x } -> ParseError (was "Expected )")
Tests pass on Scala 3.3.7, 2.13.18, 2.12.21.
References:
- google/go-jsonnet#8731 parent b861ee8 commit c7b60b3
3 files changed
Lines changed: 30 additions & 11 deletions
File tree
- sjsonnet
- src/sjsonnet
- test
- resources/test_suite
- src/sjsonnet
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
951 | 951 | | |
952 | 952 | | |
953 | 953 | | |
954 | | - | |
| 954 | + | |
955 | 955 | | |
956 | 956 | | |
957 | 957 | | |
| |||
1045 | 1045 | | |
1046 | 1046 | | |
1047 | 1047 | | |
1048 | | - | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
1049 | 1052 | | |
1050 | | - | |
1051 | | - | |
1052 | | - | |
1053 | | - | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
1054 | 1059 | | |
1055 | 1060 | | |
1056 | | - | |
1057 | | - | |
| 1061 | + | |
| 1062 | + | |
1058 | 1063 | | |
1059 | | - | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
1060 | 1069 | | |
1061 | 1070 | | |
1062 | 1071 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
| 1 | + | |
| 2 | + | |
3 | 3 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
60 | 70 | | |
61 | 71 | | |
62 | 72 | | |
| |||
0 commit comments