Skip to content

Commit a9de8c0

Browse files
committed
fix: return None for macro rule with missing param kind instead of panicking
Fixes #9797
1 parent 8dd8779 commit a9de8c0

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

crates/cairo-lang-semantic/src/expr/test_data/statements

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,35 @@ fn unstable_function_with_note() -> felt252 {
216216
//! > function_body
217217

218218
//! > expected_diagnostics
219+
220+
//! > ==========================================================================
221+
222+
//! > Declarative macro with parameter missing kind specifier.
223+
224+
//! > test_runner_name
225+
test_function_diagnostics(expect_diagnostics: true)
226+
227+
//! > function_code
228+
fn foo() {
229+
m!(1);
230+
}
231+
232+
//! > function_name
233+
foo
234+
235+
//! > module_code
236+
macro m {
237+
($x) => { 0 };
238+
}
239+
240+
//! > expected_diagnostics
241+
error[E1010]: Macro parameter must have a kind.
242+
--> lib.cairo:2:7
243+
($x) => { 0 };
244+
^
245+
246+
error[E2158]: No matching rule found in inline macro `m`.
247+
--> lib.cairo:5:5
248+
m!(1);
249+
^^^^^
250+

crates/cairo-lang-semantic/src/items/macro_declaration.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,7 @@ fn is_macro_rule_match_ex<'db>(
295295
if let ast::OptionParamKind::ParamKind(param_kind) = param.kind(db) {
296296
param_kind.kind(db).into()
297297
} else {
298-
unreachable!(
299-
"Missing macro rule param kind, should have been handled by the \
300-
parser."
301-
)
298+
return None;
302299
};
303300
let placeholder_name = param.name(db).as_syntax_node().get_text_without_trivia(db);
304301
match placeholder_kind {

0 commit comments

Comments
 (0)