Skip to content

Commit 10b72f5

Browse files
committed
Improve array pattern spread error message
1 parent fee746f commit 10b72f5

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

compiler/syntax/src/res_core.ml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,14 @@ module ErrorMessages = struct
7070
[@@live]
7171

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

8182
let record_expr_spread =
8283
"Records can only have one `...` spread, at the beginning.\n\

0 commit comments

Comments
 (0)