Skip to content

fix: return None for macro rule with missing param kind instead of panicking#9809

Open
orizi wants to merge 1 commit intoorizi/03-31-fix_missing_return_type_in_loop_bodyfrom
orizi/03-31-fix_macro_rule_missing_param_kind
Open

fix: return None for macro rule with missing param kind instead of panicking#9809
orizi wants to merge 1 commit intoorizi/03-31-fix_missing_return_type_in_loop_bodyfrom
orizi/03-31-fix_macro_rule_missing_param_kind

Conversation

@orizi
Copy link
Copy Markdown
Collaborator

@orizi orizi commented Mar 31, 2026

Summary

Fixed handling of declarative macro parameters that are missing kind specifiers by returning None instead of panicking with unreachable!(), and added a test case to verify proper error reporting for this scenario.


Type of change

Please check one:

  • Bug fix (fixes incorrect behavior)
  • New feature
  • Performance improvement
  • Documentation change with concrete technical impact
  • Style, wording, formatting, or typo-only change

Why is this change needed?

The code was using unreachable!() for a case that can actually occur when macro parameters are missing kind specifiers, causing the compiler to panic instead of gracefully handling the error and providing proper diagnostics to the user.


What was the behavior or documentation before?

When a declarative macro parameter was missing a kind specifier (e.g., ($x) instead of ($x:expr)), the compiler would panic with an "unreachable" error during macro rule matching.


What is the behavior or documentation after?

The compiler now gracefully handles missing kind specifiers by returning None from the matching function, allowing proper error diagnostics to be generated (E1010: "Macro parameter must have a kind" and E2158: "No matching rule found in inline macro").


Related issue or discussion (if any)

Fixes #9797


Additional context

The test case demonstrates that the compiler now properly reports two errors: one for the missing kind specifier in the macro definition, and another for the failed macro invocation due to no matching rules.


Note

Low Risk
Low risk: small, localized change to macro pattern matching error handling plus a regression test; behavior only changes for invalid macro definitions.

Overview
Prevents a compiler panic during declarative macro matching when a macro rule parameter has no kind specifier (e.g., ($x)), by treating that rule as a non-match (None) rather than hitting unreachable!().

Adds a semantic test case asserting the expected diagnostics for this invalid macro definition, including the missing-kind error and the subsequent "no matching rule" error at the call site.

Written by Cursor Bugbot for commit dbb21ea. This will update automatically on new commits. Configure here.

@reviewable-StarkWare
Copy link
Copy Markdown

This change is Reviewable

Copy link
Copy Markdown
Contributor

@eytan-starkware eytan-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

@eytan-starkware reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on TomerStarkware).

Copy link
Copy Markdown
Collaborator

@TomerStarkware TomerStarkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

@TomerStarkware made 1 comment.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on orizi).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Compiler panic in semantic pass: unreachable!() in is_macro_rule_match_ex for macro param without kind

4 participants