check index on placeholder (#1005)

This commit is contained in:
Marmare314 2023-04-28 18:49:21 +02:00 committed by GitHub
parent 0d8c3254b7
commit 8fa1af8ac8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -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() {

View File

@ -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