Fix "not in" precedence

This commit is contained in:
Laurenz 2023-02-12 10:17:35 +01:00
parent ebe919220d
commit 03cbdea4b4
2 changed files with 14 additions and 9 deletions

View File

@ -562,16 +562,17 @@ fn code_expr_prec(p: &mut Parser, atomic: bool, min_prec: usize) {
continue;
}
let binop = if p.eat_if(SyntaxKind::Not) {
if p.at(SyntaxKind::In) {
Some(ast::BinOp::NotIn)
let binop =
if ast::BinOp::NotIn.precedence() >= min_prec && p.eat_if(SyntaxKind::Not) {
if p.at(SyntaxKind::In) {
Some(ast::BinOp::NotIn)
} else {
p.expected("keyword `in`");
break;
}
} else {
p.expected("keyword `in`");
break;
}
} else {
ast::BinOp::from_kind(p.current())
};
ast::BinOp::from_kind(p.current())
};
if let Some(op) = binop {
let mut prec = op.precedence();

View File

@ -23,6 +23,10 @@
// Error: 3-12 cannot apply '-' to boolean
#{-not true}
---
// Not in handles precedence.
#test(-1 not in (1, 2, 3), true)
---
// Parentheses override precedence.
#test((1), 1)