Fix segfault when pattern matching on opaque types from lists #9115
+242
−50
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fix segfault (issue #9113) when pattern matching on recursive opaque types extracted from lists. This PR addresses two related issues:
1. List element re-boxing (original fix)
When a recursive opaque type (like
Element) is stored in a list, elements are auto-boxed for uniform size. When these elements are later used as tag union payloads, the code now correctly re-boxes them to match the expected layout.2. Incorrect auto-boxing in record_collect (new fix)
The
record_collectcontinuation was incorrectly auto-boxing fields based on whether the field's type is self-recursive. This caused layout mismatches when a separate recursive type (likeNodeA) was used in a different type's record field (likeNodeB'sFoldBpayload).The fix removes this incorrect auto-boxing. The type-based layout is the source of truth:
Type := [Node({ child: Type })]), the layout system correctly createsBox(Type)during layout computation.{ event: NodeA }), it should NOT be boxed becauseNodeAis already a complete type.Changes
boxbut the actual list has non-boxed elements, re-box each elementTest plan
test/fx/issue9113_simple.roc(tests list re-boxing)test/fx/list_opaque_pattern_match_bug.roc(tests nested opaque types)zig build minicipassesFixes #9113
🤖 Generated with Claude Code