Skip to content

Fix expected_type propagation for tuple-to-Array coercion in blocks#758

Merged
gfx merged 4 commits intomainfrom
claude/implement-match-constant-pattern-QgUqG
Apr 2, 2026
Merged

Fix expected_type propagation for tuple-to-Array coercion in blocks#758
gfx merged 4 commits intomainfrom
claude/implement-match-constant-pattern-QgUqG

Conversation

@gfx
Copy link
Copy Markdown
Member

@gfx gfx commented Apr 2, 2026

Summary

  • Fix match arm returning Array<Struct> from if-else producing invalid Wasmresolve_block only propagated expected_type to the last Stmt::Expr, but if-else/match/labeled-block as the last statement in a block are parsed as Stmt::If/Stmt::Match/Stmt::LabeledBlock, so the tuple-to-Array coercion via SequenceLiteralBuilder never fired, producing Wasm GC type mismatches ((ref (exact $type)) vs (ref $type)).
  • Propagate expected_type through all value-producing statement types (Stmt::If, Stmt::Match, Stmt::LabeledBlock) and expression types (Expr::Block, Expr::LabeledBlock).
  • Remove #![TODO] from match_associated_constant_pattern — the feature was already implemented; the TODO marker was stale.

Test plan

  • All 4495 e2e tests pass across O0/O1/O2/O3/Os
  • on-task-done passes (1278 tests, format, clippy, golden fixtures)
  • Manual verification of edge cases: nested if-else, nested match, labeled blocks inside match arms

https://claude.ai/code/session_01QJx35bRayRsECnakjUnGEN

claude added 4 commits April 2, 2026 12:44
The associated constant pattern feature (Type::CONST in match/matches)
is already implemented and all tests pass. Remove the stale TODO marker
and outdated comment about parser rejection.

https://claude.ai/code/session_01QJx35bRayRsECnakjUnGEN
…Wasm

The bug: when an if-else statement inside a match arm block returned
tuple literals (e.g. `[Pair { a: r, b: r }]`), the expected_type was
not propagated through, so the tuple-to-Array coercion via
SequenceLiteralBuilder never fired. This produced mismatched Wasm GC
types: `(ref (exact $type))` vs `(ref $type)`.

Root cause: `resolve_block` only propagated `expected_type` to the last
statement when it was `Stmt::Expr`, but if-else inside a match arm body
is parsed as `Stmt::If`. Added `resolve_if_stmt_with_expected` to
propagate expected_type through if statement blocks, and also propagate
expected_type through `Expr::Block` in `resolve_expr`.

https://claude.ai/code/session_01QJx35bRayRsECnakjUnGEN
The previous fix only handled Stmt::If in resolve_block. The same bug
existed for Stmt::Match and Stmt::LabeledBlock as the last statement
in a block: expected_type was not propagated, preventing tuple-to-Array
coercion via SequenceLiteralBuilder.

Also propagate expected_type through Expr::Block and Expr::LabeledBlock
in resolve_expr for the same reason.

https://claude.ai/code/session_01QJx35bRayRsECnakjUnGEN
@gfx gfx merged commit fe15e41 into main Apr 2, 2026
10 checks passed
@gfx gfx deleted the claude/implement-match-constant-pattern-QgUqG branch April 2, 2026 14:21
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.

2 participants