···620 elements_after_tail = Some(elements);
621 }
622 };
623+624+ // Give a better error when there is a another spread
625+ // like `[..wibble, wobble, ..wabble]`
626+ if self.maybe_one(&Token::DotDot).is_some() {
627+ return parse_error(
628+ ParseErrorType::ListSpreadWithAnotherSpread,
629+ SrcSpan { start, end },
630+ );
631+ }
632 };
633634 if tail.is_some() && !elements_end_with_comma {
+9
compiler-core/src/parse/error.rs
···161 "See: https://tour.gleam.run/basics/lists/".into(),
162 ],
163 ),
00000000164 ParseErrorType::ListSpreadFollowedByElements => (
165 "I wasn't expecting elements after this",
166 vec![
···389 UnknownTarget, // an unknown target was used
390 ListSpreadWithoutElements, // Pointless spread: `[..xs]`
391 ListSpreadFollowedByElements, // trying to append something after the spread: `[..xs, x]`
0392 LowcaseBooleanPattern, // most likely user meant True or False in patterns
393 UnexpectedLabel, // argument labels were provided, but are not supported in this context
394 UnexpectedEof,
···161 "See: https://tour.gleam.run/basics/lists/".into(),
162 ],
163 ),
164+ ParseErrorType::ListSpreadWithAnotherSpread => (
165+ "I wasn't expecting a spread here",
166+ vec![
167+ "Lists are immutable and singly-linked, so to join two or more lists".into(),
168+ "all the elements of the lists would need to be copied into a new list.".into(),
169+ "This would be slow, so there is no built-in syntax for it.".into(),
170+ ],
171+ ),
172 ParseErrorType::ListSpreadFollowedByElements => (
173 "I wasn't expecting elements after this",
174 vec![
···397 UnknownTarget, // an unknown target was used
398 ListSpreadWithoutElements, // Pointless spread: `[..xs]`
399 ListSpreadFollowedByElements, // trying to append something after the spread: `[..xs, x]`
400+ ListSpreadWithAnotherSpread, // trying to use multiple spreads: `[..xs, ..ys]`
401 LowcaseBooleanPattern, // most likely user meant True or False in patterns
402 UnexpectedLabel, // argument labels were provided, but are not supported in this context
403 UnexpectedEof,
···1+---
2+source: compiler-core/src/parse/tests.rs
3+expression: "\npub fn main() -> Nil {\n let xs = [1, 2, 3]\n let ys = [5, 6, 7]\n [..xs, 4, ..ys]\n}\n"
4+---
5+----- SOURCE CODE
6+7+pub fn main() -> Nil {
8+ let xs = [1, 2, 3]
9+ let ys = [5, 6, 7]
10+ [..xs, 4, ..ys]
11+}
12+13+14+----- ERROR
15+error: Syntax error
16+ ┌─ /src/parse/error.gleam:5:4
17+ │
18+5 │ [..xs, 4, ..ys]
19+ │ ^^ I wasn't expecting a spread here
20+21+Lists are immutable and singly-linked, so to join two or more lists
22+all the elements of the lists would need to be copied into a new list.
23+This would be slow, so there is no built-in syntax for it.