Skip to content

fix: handle mismatched generic param kinds in substitution rewriter instead of panicking#9815

Merged
orizi merged 1 commit intomainfrom
orizi/03-31-fix_mismatched_generic_param_in_substitution
Apr 1, 2026
Merged

fix: handle mismatched generic param kinds in substitution rewriter instead of panicking#9815
orizi merged 1 commit intomainfrom
orizi/03-31-fix_mismatched_generic_param_in_substitution

Conversation

@orizi
Copy link
Copy Markdown
Collaborator

@orizi orizi commented Mar 31, 2026

Summary

Fixed a panic in the semantic analyzer when encountering mismatched generic parameter kinds between trait and impl functions by replacing extract_matches! with proper error handling that skips diagnostics when the generic argument type doesn't match the expected type parameter.


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 semantic analyzer would panic when processing impl functions that had mismatched generic parameter kinds compared to their corresponding trait functions. Specifically, when a trait function expected a type parameter but the impl function provided an impl parameter (like +Drop<felt252>), the extract_matches! macro would panic instead of gracefully handling the mismatch.


What was the behavior or documentation before?

The code would panic with extract_matches! when trying to extract a GenericArgumentId::Type from a generic argument that was actually a different kind (like GenericArgumentId::Impl).


What is the behavior or documentation after?

The code now properly handles the mismatch by checking the generic argument type with pattern matching and returning skip_diagnostic() when the kinds don't match, allowing the previously reported diagnostic (WrongGenericParamKindForImplFunction) to be the primary error without causing a panic.


Related issue or discussion (if any)

Fixes #9798


Additional context

The test case demonstrates the specific scenario: a trait function bar<T> with a type parameter T, but an impl function bar<+Drop<felt252>> with an impl parameter. The fix ensures that the appropriate error messages are shown (E2036 for parameter name incompatibility and E2038 for generic parameter kind incompatibility) without crashing the compiler.


Note

Medium Risk
Touches core semantic substitution logic, which could affect how generics are rewritten and how errors are surfaced, but the change is narrowly scoped and guarded by an existing diagnostic path.

Overview
Fixes a crash in SubstitutionRewriter when rewriting TypeLongId::GenericParameter by replacing extract_matches! with a kind check and returning skip_diagnostic() if the substituted GenericArgumentId isn’t a Type.

Adds a regression test covering a trait method bar<T> implemented as bar<+Drop<felt252>>, asserting the expected E2036/E2038 diagnostics are emitted without panicking.

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

@reviewable-StarkWare
Copy link
Copy Markdown

This change is Reviewable

Copy link
Copy Markdown
Collaborator Author

orizi commented Mar 31, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

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).

@orizi orizi changed the base branch from orizi/03-31-fix_statement_const_in_named_arg_shorthand to graphite-base/9815 April 1, 2026 09:34
@orizi orizi force-pushed the graphite-base/9815 branch from 807d98d to 5248475 Compare April 1, 2026 09:35
@orizi orizi force-pushed the orizi/03-31-fix_mismatched_generic_param_in_substitution branch from a5034b8 to 276b712 Compare April 1, 2026 09:35
@orizi orizi changed the base branch from graphite-base/9815 to main April 1, 2026 09:35
@orizi orizi enabled auto-merge April 1, 2026 09:35
@orizi orizi added this pull request to the merge queue Apr 1, 2026
Merged via the queue into main with commit 3855e3f Apr 1, 2026
105 checks passed
@orizi orizi deleted the orizi/03-31-fix_mismatched_generic_param_in_substitution branch April 1, 2026 09:49
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: extract_matches! in SubstitutionRewriter for mismatched generic param kinds

3 participants