nickel icon indicating copy to clipboard operation
nickel copied to clipboard

Nonsensical record patterns are treated as valid

Open matthew-healy opened this issue 2 years ago • 2 comments

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.

matthew-healy avatar Feb 03 '23 10:02 matthew-healy

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

matthew-healy avatar Feb 03 '23 12:02 matthew-healy

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

yannham avatar Nov 12 '24 18:11 yannham