diff --git a/src/eval/mod.rs b/src/eval/mod.rs index 68163bf6a..2719c2989 100644 --- a/src/eval/mod.rs +++ b/src/eval/mod.rs @@ -1268,7 +1268,13 @@ impl ast::Pattern { ast::DestructuringKind::Named(named) => { bail!(named.span(), "cannot destructure named elements from an array") } - ast::DestructuringKind::Placeholder(_) => i += 1, + ast::DestructuringKind::Placeholder(underscore) => { + if i < value.len() { + i += 1 + } else { + bail!(underscore.span(), "not enough elements to destructure") + } + } } } if i < value.len() { diff --git a/tests/typ/compiler/let.typ b/tests/typ/compiler/let.typ index 7081bcf05..d9940a8c3 100644 --- a/tests/typ/compiler/let.typ +++ b/tests/typ/compiler/let.typ @@ -177,6 +177,12 @@ Three #let (a, ..) = (a: 1, b: 2) #test(a, 1) +--- +// Trailing placeholders. +// Error: 10-11 not enough elements to destructure +#let (a, _, _, _, _) = (1,) +#test(a, 1) + --- // Error: 10-13 expected identifier, found string // Error: 18-19 expected identifier, found integer