From 03cbdea4b4dd81929743154ad79835bfbdf63db3 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sun, 12 Feb 2023 10:17:35 +0100 Subject: [PATCH] Fix "not in" precedence --- src/syntax/parser.rs | 19 ++++++++++--------- tests/typ/compiler/ops-prec.typ | 4 ++++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/syntax/parser.rs b/src/syntax/parser.rs index 9f951389d..8082fd649 100644 --- a/src/syntax/parser.rs +++ b/src/syntax/parser.rs @@ -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(); diff --git a/tests/typ/compiler/ops-prec.typ b/tests/typ/compiler/ops-prec.typ index 2fa90382d..e243a6402 100644 --- a/tests/typ/compiler/ops-prec.typ +++ b/tests/typ/compiler/ops-prec.typ @@ -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)