mirror of
https://github.com/typst/typst
synced 2025-05-20 20:15:29 +08:00
Fix duplicate error message for destructuring
This commit is contained in:
parent
58e4bdb1b9
commit
9720424884
@ -1461,16 +1461,16 @@ impl Eval for ast::ForLoop {
|
|||||||
|
|
||||||
match (pattern.kind(), iter.clone()) {
|
match (pattern.kind(), iter.clone()) {
|
||||||
(ast::PatternKind::Ident(_), Value::Str(string)) => {
|
(ast::PatternKind::Ident(_), Value::Str(string)) => {
|
||||||
// iterate over characters of string
|
// Iterate over graphemes of string.
|
||||||
iter!(for pattern in string.as_str().graphemes(true));
|
iter!(for pattern in string.as_str().graphemes(true));
|
||||||
}
|
}
|
||||||
(_, Value::Dict(dict)) => {
|
(_, Value::Dict(dict)) => {
|
||||||
// iterate over keys of dict
|
// Iterate over pairs of dict.
|
||||||
iter!(for pattern in dict.pairs());
|
iter!(for pattern in dict.pairs());
|
||||||
}
|
}
|
||||||
(_, Value::Array(array)) => {
|
(_, Value::Array(array)) => {
|
||||||
// iterate over values of array and allow destructuring
|
// Iterate over values of array.
|
||||||
iter!(for pattern in array.into_iter());
|
iter!(for pattern in array);
|
||||||
}
|
}
|
||||||
(ast::PatternKind::Ident(_), _) => {
|
(ast::PatternKind::Ident(_), _) => {
|
||||||
bail!(self.iter().span(), "cannot loop over {}", iter.type_name());
|
bail!(self.iter().span(), "cannot loop over {}", iter.type_name());
|
||||||
|
@ -853,16 +853,9 @@ fn pattern(p: &mut Parser) -> PatternKind {
|
|||||||
|
|
||||||
PatternKind::Destructuring
|
PatternKind::Destructuring
|
||||||
} else {
|
} else {
|
||||||
let success = p.expect(SyntaxKind::Ident);
|
if p.expect(SyntaxKind::Ident) {
|
||||||
if p.at(SyntaxKind::Comma) {
|
|
||||||
// TODO: this should only be a warning instead
|
|
||||||
p.expected("keyword `in`. did you mean to use a destructuring pattern?");
|
|
||||||
}
|
|
||||||
|
|
||||||
if success {
|
|
||||||
p.wrap(m, SyntaxKind::Pattern);
|
p.wrap(m, SyntaxKind::Pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
PatternKind::Normal
|
PatternKind::Normal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -964,7 +957,13 @@ fn for_loop(p: &mut Parser) {
|
|||||||
let m = p.marker();
|
let m = p.marker();
|
||||||
p.assert(SyntaxKind::For);
|
p.assert(SyntaxKind::For);
|
||||||
pattern(p);
|
pattern(p);
|
||||||
p.expect(SyntaxKind::In);
|
if p.at(SyntaxKind::Comma) {
|
||||||
|
p.expected("keyword `in`. did you mean to use a destructuring pattern?");
|
||||||
|
p.eat_if(SyntaxKind::Ident);
|
||||||
|
p.eat_if(SyntaxKind::In);
|
||||||
|
} else {
|
||||||
|
p.expect(SyntaxKind::In);
|
||||||
|
}
|
||||||
code_expr(p);
|
code_expr(p);
|
||||||
block(p);
|
block(p);
|
||||||
p.wrap(m, SyntaxKind::ForLoop);
|
p.wrap(m, SyntaxKind::ForLoop);
|
||||||
|
@ -93,7 +93,6 @@
|
|||||||
---
|
---
|
||||||
// Destructuring without parentheses.
|
// Destructuring without parentheses.
|
||||||
// Error: 7 expected keyword `in`. did you mean to use a destructuring pattern?
|
// Error: 7 expected keyword `in`. did you mean to use a destructuring pattern?
|
||||||
// Error: 7 expected keyword `in`
|
|
||||||
#for k, v in (a: 4, b: 5) {
|
#for k, v in (a: 4, b: 5) {
|
||||||
dont-care
|
dont-care
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user