Skip to content

Improve array pattern spread error message #7549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 15, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve array pattern spread error message
  • Loading branch information
mediremi committed Jun 13, 2025
commit 10b72f5558bbd97a143c70040fa259d273847bcd
15 changes: 8 additions & 7 deletions compiler/syntax/src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,14 @@ module ErrorMessages = struct
[@@live]

let array_pattern_spread =
"Array spread (`...`) is not supported in pattern matches.\n\
Explanation: such spread would create a subarray; out of performance \
concern, our pattern matching currently guarantees to never create new \
intermediate data.\n\
Solution: if it's to validate the first few elements, use an `if` clause \
+ Array length check + `get` checks on the current pattern. If it's to \
obtain a subarray, use `Array.slice`."
"Array spread (`...`) is not supported in pattern matches.\n\n\
Explanation: Allowing `...` here would require creating a new subarray at \
match time, but for performance reasons pattern matching is guaranteed to \
never create intermediate data.\n\n\
Possible solutions:\n\
- To validate specific elements: Use `if` with length checks and \
`Array.get`\n\
- To extract a subarray: Use `Array.slice`"

let record_expr_spread =
"Records can only have one `...` spread, at the beginning.\n\
Expand Down
Loading