nickel
nickel copied to clipboard
Nonsensical record patterns are treated as valid
Describe the bug
Currently patterns like the following evaluate successfully:
let r = { a = 1, b = 2 } in
let { a, a, .. } = r in # note the repetition of "a"
a # evaluates to 1
Expected behavior
When patterns are "compiled" into Destruct representations we should detect repeated identifiers & raise an error.
An even worse example of the above:
let { a, b = a, .. } = { a = 1, b = 2 } in
a # evaluates to 1
let { b = a, a, .. } = { a = 1, b = 2 } in
a # evaluates to 2
The first example now fails with a proper error message. However, the two others fail with a rather cryptic message that is due to how pattern matching is desugared, which is clearly still to be fixed:
nickel> let { a, b = a, .. } = { a = 1, b = 2 } in
a # evaluates to 1
error: record/insert: tried to extend a record with the field a, but it already exists
nickel> let { b = a, a, .. } = { a = 1, b = 2 } in
a # evaluates to 2
error: record/insert: tried to extend a record with the field a, but it already exists