From a9de8c0deef5b79ad92391805b8869a04ece63df Mon Sep 17 00:00:00 2001 From: Ori Ziv Date: Tue, 31 Mar 2026 18:10:42 +0300 Subject: [PATCH] fix: return None for macro rule with missing param kind instead of panicking Fixes #9797 --- .../src/expr/test_data/statements | 32 +++++++++++++++++++ .../src/items/macro_declaration.rs | 5 +-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/crates/cairo-lang-semantic/src/expr/test_data/statements b/crates/cairo-lang-semantic/src/expr/test_data/statements index a17045609d3..2f067833691 100644 --- a/crates/cairo-lang-semantic/src/expr/test_data/statements +++ b/crates/cairo-lang-semantic/src/expr/test_data/statements @@ -216,3 +216,35 @@ fn unstable_function_with_note() -> felt252 { //! > function_body //! > expected_diagnostics + +//! > ========================================================================== + +//! > Declarative macro with parameter missing kind specifier. + +//! > test_runner_name +test_function_diagnostics(expect_diagnostics: true) + +//! > function_code +fn foo() { + m!(1); +} + +//! > function_name +foo + +//! > module_code +macro m { + ($x) => { 0 }; +} + +//! > expected_diagnostics +error[E1010]: Macro parameter must have a kind. + --> lib.cairo:2:7 + ($x) => { 0 }; + ^ + +error[E2158]: No matching rule found in inline macro `m`. + --> lib.cairo:5:5 + m!(1); + ^^^^^ + diff --git a/crates/cairo-lang-semantic/src/items/macro_declaration.rs b/crates/cairo-lang-semantic/src/items/macro_declaration.rs index 02ceceb8f15..9cdfee16155 100644 --- a/crates/cairo-lang-semantic/src/items/macro_declaration.rs +++ b/crates/cairo-lang-semantic/src/items/macro_declaration.rs @@ -295,10 +295,7 @@ fn is_macro_rule_match_ex<'db>( if let ast::OptionParamKind::ParamKind(param_kind) = param.kind(db) { param_kind.kind(db).into() } else { - unreachable!( - "Missing macro rule param kind, should have been handled by the \ - parser." - ) + return None; }; let placeholder_name = param.name(db).as_syntax_node().get_text_without_trivia(db); match placeholder_kind {