Skip to content

fix: emit diagnostic for member access on unreduced impl type instead of panicking#9807

Open
orizi wants to merge 1 commit intoorizi/03-31-fix_unsupported_items_in_statement_positionfrom
orizi/03-31-fix_member_access_on_unreduced_impl_type
Open

fix: emit diagnostic for member access on unreduced impl type instead of panicking#9807
orizi wants to merge 1 commit intoorizi/03-31-fix_unsupported_items_in_statement_positionfrom
orizi/03-31-fix_member_access_on_unreduced_impl_type

Conversation

@orizi
Copy link
Copy Markdown
Collaborator

@orizi orizi commented Mar 31, 2026

Summary

Replace unreachable panic with proper error handling for member access on unreduced impl associated types. When attempting to access members on ImplType, the code now reports a TypeHasNoMembers diagnostic instead of panicking with an unreachable statement.


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 previous implementation would panic with an unreachable statement when encountering member access on unreduced impl associated types (like H::A in generic contexts). This caused the compiler to crash instead of providing a helpful error message to users.


What was the behavior or documentation before?

When accessing members on unreduced impl associated types, the compiler would panic with the message "Impl type should've been reduced" and crash.


What is the behavior or documentation after?

The compiler now gracefully handles this case by reporting error E2057: "Type has no members" with the specific type and member name, allowing compilation to continue and providing better user experience.


Related issue or discussion (if any)

Fixes #9788


Additional context

The change also removes an unused import cairo_lang_debug::DebugWithDb that was only used in the removed unreachable statement. A test case has been added to verify the new error handling behavior works correctly for generic impl associated types.


Note

Low Risk
Low risk: replaces an unreachable! panic with a standard error path for a specific type case, plus a focused regression test.

Overview
Prevents the semantic analyzer from panicking when performing member access on an unreduced ImplType (e.g. H::A) by reporting TypeHasNoMembers instead.

Removes the now-unused debug import used only for the panic message, and adds a regression test ensuring the new E2057 diagnostic is produced for generic impl-associated type member access.

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

@reviewable-StarkWare
Copy link
Copy Markdown

This change is Reviewable

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

TypeLongId::ImplType(_) => Err(ctx.diagnostics.report(
rhs_syntax.stable_ptr(db),
TypeHasNoMembers { ty: long_ty.intern(ctx.db), member_name },
)),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Duplicate match arm could be combined with existing

Low Severity

The new TypeLongId::ImplType(_) arm produces an identical TypeHasNoMembers diagnostic to the existing TypeLongId::GenericParameter(_) | TypeLongId::Coupon(_) arm just below it. These could be combined into a single pattern arm (ImplType(_) | GenericParameter(_) | Coupon(_)), reducing duplication and ensuring future changes to the diagnostic stay consistent across all three variants.

Additional Locations (1)
Fix in Cursor Fix in Web

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

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.

@eytan-starkware reviewed 2 files and all commit messages, and made 2 comments.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on orizi and TomerStarkware).


crates/cairo-lang-semantic/src/expr/compute.rs line 3960 at r1 (raw file):

        TypeLongId::ImplType(_) => Err(ctx.diagnostics.report(
            rhs_syntax.stable_ptr(db),
            TypeHasNoMembers { ty: long_ty.intern(ctx.db), member_name },

Consider an informative error and not just has no members.

TypeLongId::ImplType(_) => Err(ctx.diagnostics.report(
rhs_syntax.stable_ptr(db),
TypeHasNoMembers { ty: long_ty.intern(ctx.db), member_name },
)),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

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.

3 participants