Skip to content

Conversation

@rtfeldman
Copy link
Contributor

This fixes a panic ("reached unreachable code") that occurred when creating a list literal inside a for loop over a polymorphic list parameter.

The bug happened because when a polymorphic function contains a for loop that iterates over a polymorphic list parameter and creates a new list literal from the loop element (e.g., [e]), the interpreter expected the list's compile-time type to be a concrete List(elem) structure. However, in polymorphic contexts, the list type was a flex variable, causing an assertion failure.

  • Added fallback logic in e_list handling to get element type from the first element's compile-time type when the list type is not a structure
  • Added regression test in test/fx/issue8898.roc with corresponding test in fx_platform_test.zig

Fixes #8898

Co-authored by Claude Opus 4.5

When a polymorphic function contains a for loop that iterates over a
polymorphic list parameter, and creates a new list literal from the
loop element (e.g., [e]), the interpreter would panic with "reached
unreachable code" because runtime type unification could fail and
corrupt the argument types to .err.

The fix: In prepareCallWithFuncVar, take a snapshot of the runtime
types before unification, and roll back if unification fails. This
preserves the original types and prevents corruption. Unification
failures can occur in polymorphic contexts due to type reuse across
iterations, but since the code passed compile-time type checking,
we can safely continue with the original types.

The e_list handler now uses debug assertions instead of a fallback,
as the type corruption issue is addressed at its source.

Fixes #8898

🤖 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 January 3, 2026 21:56
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

Test panic: reached unreachable code

2 participants