Skip to content

fix(hir): infer array mapping results independently of input types - #11461

Merged
proggeramlug merged 2 commits into
mainfrom
fix/11446-map-task-match
Sep 27, 2026
Merged

proggeramlug merged 2 commits into
mainfrom
fix/11446-map-task-match

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #11446.

Array.map and flatMap inherited the input element type in the early AST inference table. Mapping cron expression strings to task objects therefore left tasks typed as string[], and tasks[0].match(date) took the string fast path and returned null instead of calling the task's method.

Infer an unknown result element type at that callee-only stage and let the existing callback-aware HIR inference refine it. Element-preserving methods keep their existing types. Add lowering tests and a native parity fixture for mapped class methods, flatMap, and string/numeric results.

Validation:

  • Fresh main reproduces the node-cron failure and the small native fixture (null for both mapping methods).
  • HIR unit suite: 527 passed, one ignored, including all three new inference tests.
  • Native parity fixture matches Node 26.5.1. Real node-cron@4.6.0 reproducer returns true through map; its four-task benchmark (2,000 warmup + 50,000 measured iterations) matches Node checksum 70e63a61.
  • Node-version consistency, Rust file-size, formatting, and diff checks pass.

No version bump.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed type inference for array map and flatMap operations so results reflect the values produced by their callbacks, including when operations are chained.
    • Improved handling of mapped class instances and string or numeric results, while preserving element types for array operations that retain the original elements.

@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 34319bf3-e091-4ee0-9909-d236a5778eb8

📥 Commits

Reviewing files that changed from the base of the PR and between d1ae277 and 77db230.

📒 Files selected for processing (4)
  • changelog.d/11461-array-mapping-result-types.md
  • crates/perry-hir/src/lower_types.rs
  • crates/perry-hir/src/lower_types/array_mapping_tests.rs
  • test-files/test_gap_11446_array_mapping_result_types.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

Array map and flatMap now begin with Array<Any> result types instead of inheriting the source element type. HIR tests and a TypeScript regression test cover callback result inference and type preservation in other array operations.

Changes

Array mapping inference

Layer / File(s) Summary
Provisional mapping result types
crates/perry-hir/src/lower_types.rs
map and flatMap now return Array<Any> during early inference. Other listed array methods continue to return the receiver type.
Mapping inference coverage
crates/perry-hir/src/lower_types/array_mapping_tests.rs, test-files/test_gap_11446_array_mapping_result_types.ts, changelog.d/11461-array-mapping-result-types.md
HIR and TypeScript tests cover callback-derived map and flatMap results and chained operations that preserve array element types. The changelog records the inference change and coverage.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 77db2

The regression fixture checks mapped-object behavior against Node, and no remaining issue has been identified that would prevent merging after normal checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 3 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: independent inference for array mapping results.
Description check ✅ Passed The description explains the defect, the fix, the related issue, and the validation results. It does not reproduce the template headings or checklist, but it contains the required substantive informat…
Linked Issues check ✅ Passed The PR addresses the coding objective in [#11446]. infer_call_return_type now gives map and flatMap an independent Array<Any> result instead of reusing the receiver element type. Callback-awar…
Out of Scope Changes check ✅ Passed The changed files stay within [#11446]. The type-inference change fixes the mapped-result behavior. The lowering tests, runtime parity fixture, and changelog document and validate that fix. No unrelat…
Full details: Docstring Coverage

Explanation

Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 3 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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 merged commit d7f556f into main Sep 27, 2026
55 of 57 checks passed
@proggeramlug
proggeramlug deleted the fix/11446-map-task-match branch September 27, 2026 04:18
@proggeramlug

Copy link
Copy Markdown
Contributor Author

Independent verification on perrymaster (Linux x86-64, Node 26.5.1, --profile perry-dev, compiler plus both static wrappers rebuilt, PERRY_NO_AUTO_OPTIMIZE=1):

Not run: HIR unit tests (the PR reports them), the full gap sweep, and macOS.

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.

node-cron: task.match(date) returns null for tasks created inside Array.map (true on Node)

1 participant