Skip to content

Conversation

@rtfeldman
Copy link
Contributor

Summary

  • Fix pattern matching on recursive tag union variant payloads
  • When extracting payload from a recursive variant like Wrapper(Tree), use the actual variant layout from tag union data instead of computing from type

Test plan

  • Added test case test/fx/direct_recursive_tag_union.roc
  • zig build minici passes

Fixes #8754

🤖 Generated with Claude Code

When extracting payload from a recursive tag union variant like Wrapper(Tree)
where Tree := [..., Wrapper(Tree)], the payload is stored as a Box in memory.
The extractTagValue function was incorrectly computing the payload layout
from the type (which gives Tree's layout) instead of using the actual variant
layout from the tag union data (which correctly shows it as a Box).

This caused the bound payload value to have the wrong layout, leading to
incorrect pattern matching when the payload was later matched against.

The fix is to use acc.getVariantLayout(tag_index) instead of computing
the layout from the type variable. This ensures we get the correct .box
layout for recursive variant payloads.

Fixes #8754

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@rtfeldman rtfeldman marked this pull request as ready for review December 31, 2025 14:46
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.

Crash with direct recursive reference in tag union variant

2 participants