Skip to content

Implement reassignment for arrays declared using const generics#7601

Open
ironcev wants to merge 3 commits intomasterfrom
ironcev/const-generic-array-not-an-indexable-type
Open

Implement reassignment for arrays declared using const generics#7601
ironcev wants to merge 3 commits intomasterfrom
ironcev/const-generic-array-not-an-indexable-type

Conversation

@ironcev
Copy link
Copy Markdown
Member

@ironcev ironcev commented Apr 23, 2026

Description

This PR implements reassignments for arrays declared using const generic arguments:

fn const_generic_array<const N: u64>() -> [u8; N] {
    let mut res = [0u8; N];
    res[0] = 1;          // <<<<--- This now works.
    res
}

During development and testing of this PR, several other issues are found. Those issues will be addressed in separate PS, and are marked as TODOs in code, linking to their appropriate GitHub issues.

Checklist

  • I have linked to any relevant issues.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation where relevant (API docs, the reference, and the Sway book).
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added (or requested a maintainer to add) the necessary Breaking* or New Feature labels where relevant.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@ironcev ironcev self-assigned this Apr 23, 2026
@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 23, 2026

PR Summary

Medium Risk
Touches semantic-analysis projection typing and compile-time array bounds checking, which can affect correctness of indexing/reassignment and error reporting across many programs. Changes are localized but in a core type-checking path and add/adjust multiple e2e snapshots.

Overview
Enables array element projection/type resolution to work for arrays whose length is not a compile-time literal (e.g., const-generic [T; N]), while still emitting ArrayOutOfBounds only when both the index and the array length can be evaluated as literals.

Updates diagnostics/help text for NotIndexable to mention generic arrays/references, renames the negative test program array_bad_index to array_invalid_index_type, and expands array_oob_const_index to cover global/local const indices and const-generic lengths (with updated snapshot expectations).

Adds a new should-pass e2e program const_generics_array_in_reassignments to validate reassignment/indexing on const-generic arrays and nested arrays.

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

@ironcev ironcev added compiler General compiler. Should eventually become more specific as the issue is triaged compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen labels Apr 23, 2026
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, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 0b272f5. Configure here.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 23, 2026

Merging this PR will degrade performance by 16.01%

❌ 1 regressed benchmark
✅ 24 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
tokens_for_program 534.4 µs 636.3 µs -16.01%

Comparing ironcev/const-generic-array-not-an-indexable-type (217ecd1) with master (e12e611)

Open in CodSpeed

@ironcev
Copy link
Copy Markdown
Member Author

ironcev commented Apr 23, 2026

👍

@ironcev ironcev deployed to fuel-sway-bot April 23, 2026 20:47 — with GitHub Actions Active
@ironcev ironcev marked this pull request as ready for review April 23, 2026 20:48
@ironcev ironcev requested a review from a team as a code owner April 23, 2026 20:48
@ironcev ironcev enabled auto-merge (squash) April 23, 2026 20:48
@ironcev ironcev requested a review from xunilrj April 23, 2026 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen compiler General compiler. Should eventually become more specific as the issue is triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reassignment to const generic array emits "Type is not indexable" error

1 participant