Skip to content

fix(indexing): classify string receivers behind array claims (#7891) - #7904

Merged
proggeramlug merged 2 commits into
mainfrom
fix/7891-runtime-string-index
Aug 12, 2026
Merged

fix(indexing): classify string receivers behind array claims (#7891)#7904
proggeramlug merged 2 commits into
mainfrom
fix/7891-runtime-string-index

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Closes #7891.

What changed

  • keep an SSO receiver boxed when a string-valued key is read through an erased Array declaration
  • classify heap String receivers by their GC header before the array by-name fallback
  • leave the numeric guarded-array tier unchanged
  • add IR gates for the string-key and numeric-key siblings plus a runtime heap-string unit test
  • add source parity coverage for literal/dynamic keys, heap/SSO strings, arrays, objects, and the existing direct-string behavior

Reproduction

On current main, the new fixture printed undefined/s for the declared receiver while Node printed s/s. The direct any control already printed s/s in both.

Validation

  • focused codegen tests: 2 passed
  • focused runtime test: 1 passed
  • cargo test -p perry-codegen: passed, including integration and doc tests
  • exact wrapper build: -p perry -p perry-runtime-static -p perry-stdlib-static
  • fixture: Perry exit 0, Node exit 0, byte-exact output
  • test-registration check: 197 files across 4 registries
  • file-size gate: passed

Summary by CodeRabbit

  • Bug Fixes

    • Fixed numeric string-key access when values declared as arrays contain runtime strings.
    • Preserved expected string indexing and length property behavior across declared, nullable, parsed, and dynamic values.
    • Maintained correct behavior for ordinary arrays and object property lookups.
  • Tests

    • Added regression coverage for string receivers, numeric and non-numeric keys, short parsed strings, and fallback scenarios.

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

No new commits to review since the last review.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: a7811c45-53e5-4b09-9552-99b4b4560e34

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 348e3a7e-cd80-443c-87ed-6935fc372c51

📥 Commits

Reviewing files that changed from the base of the PR and between 6d9f12e and 1237c12.

📒 Files selected for processing (7)
  • changelog.d/7904-declared-array-string-index.md
  • crates/perry-codegen/src/expr/index_get.rs
  • crates/perry-codegen/src/expr/index_get_claim_tests.rs
  • crates/perry-codegen/src/expr/mod.rs
  • crates/perry-runtime/src/array/indexing.rs
  • test-files/test_gap_7890_declared_array_receiver_element_read.ts
  • test-files/test_gap_7891_string_receiver_numeric_string_key.ts

📝 Walkthrough

Walkthrough

The change fixes numeric string-key reads when a runtime string passes through an erased array declaration. Code generation preserves boxed SSO string handling, runtime lookup classifies heap strings, and regression tests cover both compiler IR and end-to-end behavior.

Changes

Declared array string-key indexing

Layer / File(s) Summary
Runtime string receiver classification
crates/perry-runtime/src/array/indexing.rs
Heap string receivers now resolve numeric keys through string indexing while preserving length and ordinary property fallback.
Claimed-array dispatch
crates/perry-codegen/src/expr/index_get.rs, crates/perry-codegen/src/expr/index_get_claim_tests.rs, crates/perry-codegen/src/expr/mod.rs
Declared-array lowering excludes static string and symbol keys from numeric claims and uses tag-aware boxed dispatch for non-numeric keys. IR tests verify string and numeric paths.
Regression coverage and changelog
test-files/test_gap_7891_string_receiver_numeric_string_key.ts, test-files/test_gap_7890_declared_array_receiver_element_read.ts, changelog.d/7904-declared-array-string-index.md
End-to-end tests cover string receivers, nullable values, arrays, direct strings, and ordinary objects. Comments and the changelog describe the handling.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant DeclaredArrayRead
  participant CodegenDispatch
  participant RuntimeArrayLookup
  participant RuntimeStringIndexing
  DeclaredArrayRead->>CodegenDispatch: Lower declared-array key read
  CodegenDispatch->>RuntimeStringIndexing: SSO receiver with numeric string key
  CodegenDispatch->>RuntimeArrayLookup: Other receiver or fallback property lookup
  RuntimeArrayLookup->>RuntimeStringIndexing: Heap string with numeric key
Loading

Possibly related PRs

  • PerryTS/perry#7890: Adds the declared-array claim handling that this change extends for string-key dispatch.
  • PerryTS/perry#7893: Establishes related declared-array key classification in index_get.rs.
  • PerryTS/perry#6888: Adds the SSO-safe boxed string-indexing behavior extended here.

Suggested reviewers: thehypnoo

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes fix string-key reads on runtime strings behind erased array declarations while preserving numeric-key behavior and adding the required regression coverage.
Out of Scope Changes check ✅ Passed All changes support issue #7891, including code fixes, regression tests, source coverage, and a changelog entry.
Title check ✅ Passed The title clearly and concisely identifies the primary fix: classifying string receivers behind erased array declarations.
Description check ✅ Passed The description covers the fix, related issue, implementation changes, reproduction, and detailed validation; omitted template headings are non-critical.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/7891-runtime-string-index

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@proggeramlug
proggeramlug marked this pull request as ready for review August 12, 2026 03:59
@proggeramlug

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
⚠️ Action not completed

Already reviewed.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@proggeramlug
proggeramlug merged commit d3dbcab into main Aug 12, 2026
1 of 19 checks passed
@proggeramlug
proggeramlug deleted the fix/7891-runtime-string-index branch August 12, 2026 04:17
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.

xs["0"] reads undefined on a string-valued receiver whose declared type is an array

1 participant