Getting record_insert: tried to extend but already exists
when using patterns with duplicate bound variables
#1906
Labels
Describe the bug
When using a pattern with duplicate bound variables, a match expression will fail at runtime with a strange and non-localized
error: record_insert: tried to extend a record with the field y, but it already exists
. This error leaks implementation details.To Reproduce
Expected behavior
One approach would be to forbid such patterns. For example, Rust forbid this and would error out with
error[E0416]: identifier
yis bound more than once in the same pattern
. Same for OCaml:Error: Variable x is bound several times in this matching
. This would technically be a breaking change, and this is why it was kept legal for destructuring (see #1324), but relying on this feature is very dubious.Another solution would be to use
update
instead ofinsert
when compiling patterns, so that we can handle several occurrences. But I don't have a good use-case for this, so I'm in favor of just making this illegal.The text was updated successfully, but these errors were encountered: