Skip to content

Bug: Option array literals with Some payloads fail codegen #586

Closed

Description

@ehartford

Summary

An array literal whose element type is Option[T] fails MIR/codegen when one or more elements are Some(payload). The compiler reports aggregate enum payload missing destination payload type instead of lowering the aggregate.

Minimal reproduction

fn main:
    let opts: [?i32] = [Some(1), None, Some(4)]
    assert(opts.len() == 3)

Expected behavior

The array literal should lower as a homogeneous [?i32] aggregate, with Some payload destinations typed from the array element type.

Actual behavior

Using WITH=$PWD/out/bin/with ./out/release/bin/with test test/behavior/behav_for_full_patterns.w while developing #439 produced:

error: aggregate enum payload missing destination payload type fn=test_enum_pattern_filters variant=0
error: code generation failed

Notes

This was discovered while adding #439 for-loop pattern tests. The #439 test now uses a Vec[?i32] sequence so it can exercise for-pattern filtering without depending on this aggregate-codegen bug.

Activity

  1. ehartford commented on Jul 2, 2026

    @ehartford
    ContributorAuthor

    Fixed by the commit above: array-literal elements now lower under the array's ELEMENT type instead of the leaked ambient annotation type (NK_ARRAY_LIT per-element expected_type rebind, the NK_TUPLE pattern). let opts: [?i32; 3] = [Some(1), None, Some(4)] and the un-annotated form both work with correct values — the un-annotated form was previously SILENTLY CORRUPTED, which this fix also cures. Pinned by behav_option_array_literal (value asserts, both forms). Note: the length-less [?i32] BINDING annotation is a separate pre-existing bug (not a spec type, corrupt slice view) — filed as #622 with a plain-int repro. §4.3c; full gates green.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions