-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix panic on duplicated top-level idents in record destructuring (#1324)
Previously Nickel would panic when encountering code like this: ``` let f = fun { x, x } = x in f { x = 1 } ``` This commit fixes that by checking each destructured record pattern for duplciated identifiers at parsing time, and returning an error if any are encountered. Note, however, that in order to preserve backwards compatibility with Nickel 1.0, the following code is still valid (and returns `1`): ``` let f = fun { x = { y }, z = { y } } => y in f { x = { y = 1 }, z = { y = 2 } } ```
- Loading branch information
1 parent
52d08c5
commit 9a2e2fc
Showing
10 changed files
with
136 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
tests/integration/destructuring/pass/nested_duplicated_ident.ncl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# test.type = 'pass' | ||
let f = fun { x = { y }, z = { y } } => y in | ||
let result = f { x = { y = 1 }, z = { y = 2 } } in | ||
result == 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,9 @@ | ||
# test.type = 'error' | ||
# | ||
# [test.metadata] | ||
# error = 'TypecheckError::MissingRow' | ||
# error = 'ParseError::DuplicateIdentInRecordPattern' | ||
# | ||
# [test.metadata.expectation] | ||
# ident = 'a' | ||
|
||
# Note: currently repeated identifiers in patterns aren't caught unless | ||
# we're in typechecking mode. there's an open issue for this (#1098) | ||
( | ||
let { a, a, .. } = { a = 1, b = 2 } in | ||
a : Number | ||
): _ | ||
# ident = 'duped' | ||
let f = fun { duped, duped, .. } => duped | ||
in f { duped = 1, other = "x" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# test.type = 'error' | ||
# | ||
# [test.metadata] | ||
# error = 'ParseError::DuplicateIdentInRecordPattern' | ||
# | ||
# [test.metadata.expectation] | ||
# ident = 'a' | ||
( | ||
let { a, a, .. } = { a = 1, b = 2 } in | ||
a : Number | ||
): _ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
tests/snapshot/inputs/errors/record_destructuring_duplicate_ident.ncl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# capture = 'stderr' | ||
# command = [] | ||
let f = fun { one, two, one } => { one, two } | ||
in f { one = 1, two = "2" } |
13 changes: 13 additions & 0 deletions
13
...s/snapshot/snapshots/snapshot__error_stderr_record_destructuring_duplicate_ident.ncl.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
source: tests/snapshot/main.rs | ||
expression: err | ||
--- | ||
error: duplicated binding `one` in record pattern | ||
┌─ [INPUTS_PATH]/errors/record_destructuring_duplicate_ident.ncl:3:25 | ||
│ | ||
3 │ let f = fun { one, two, one } => { one, two } | ||
│ --- ^^^ duplicated binding here | ||
│ │ | ||
│ previous binding here | ||
|
||
|