Skip to content

Fix ICE and type mismatch with array type aliases and const generics#7638

Open
Dnreikronos wants to merge 3 commits into
FuelLabs:masterfrom
Dnreikronos:fix/type-alias-array-const-generics-ice
Open

Fix ICE and type mismatch with array type aliases and const generics#7638
Dnreikronos wants to merge 3 commits into
FuelLabs:masterfrom
Dnreikronos:fix/type-alias-array-const-generics-ice

Conversation

@Dnreikronos
Copy link
Copy Markdown
Contributor

Summary

  • Fix ICE "Const generic not materialized" when type aliases for arrays (e.g. type ArrayU8Len2 = [u8; 2]) are used as struct fields and compared via ==
  • extract_type_parameters now extracts const generic length parameters from array types (e.g. N → 2), matching the existing pattern used for Enum/Struct const generics
  • MaterializeConstGenerics for TypeId now handles TypeInfo::Alias by recursing into the aliased type, consistent with the existing Ref handling

Test plan

  • New e2e test type_alias_array_const_generics covering:
    • Struct fields typed as array aliases
    • Nested array aliases ([ArrayU8Len2; 3])
    • Equality comparison triggering Eq trait const generic path
    • Vec<Alias>::get().unwrap() return type resolution
  • All existing type_alias* tests pass (11/11)
  • All existing const_generic* tests pass (3/3)
  • All existing array* tests pass (18/18)

Closes #7616

extract_type_parameters ignored array lengths when matching concrete
arrays against generic impls like [T; N], so N was never mapped to its
literal value. Additionally, MaterializeConstGenerics did not recurse
through TypeInfo::Alias, stopping materialization at the alias boundary.

Closes FuelLabs#7616
Covers struct fields typed as array aliases, nested aliases, equality
via the Eq trait, and Vec<Alias>::get().unwrap() return type resolution.
@Dnreikronos Dnreikronos requested a review from a team as a code owner May 26, 2026 18:06
@fuel-cla-bot
Copy link
Copy Markdown

fuel-cla-bot Bot commented May 26, 2026

Thanks for the contribution! Before we can merge this, we need @Dnreikronos to sign the Fuel Labs Contributor License Agreement.

@cursor
Copy link
Copy Markdown

cursor Bot commented May 26, 2026

PR Summary

Medium Risk
Touches core type-system const-generic and unification paths in sway-core; scope is narrow but compiler correctness is sensitive.

Overview
Fixes an ICE (Const generic not materialized) and related type mismatches when array type aliases (e.g. type ArrayU8Len2 = [u8; 2]) appear in struct fields, ==, and generic APIs like Vec<Alias>::get().

MaterializeConstGenerics on TypeId now handles TypeInfo::Alias by materializing through the aliased type and re-inserting the alias, mirroring existing Ref behavior.

extract_type_parameters for Array now pairs element types and lengths: when the original length is an ambiguous const-generic name and the concrete side is a literal, it records that binding (same idea as struct/enum const generics).

Adds e2e type_alias_array_const_generics (nested aliases, equality, Vec + unwrap).

Reviewed by Cursor Bugbot for commit 828f7ea. Bugbot is set up for automated code reviews on this repo. Configure here.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ICE and wrong type mismatch error when using type aliases and traits implemented for const generics arrays

1 participant