Skip to content

Union with only []type fields causes compile error #25944

Description

@0x6a62

Zig Version

0.15.2
0.16.0-dev.1316+181b25ce4

Steps to Reproduce and Observed Behavior

Description

When a union has all of it's fields of type []const type, I get the compile error: [@enumFromInt(26829)]: 8 != 1

In case it matters, this is on 64bit Linux.

Examples

Causes compile error:

const std = @import("std");

// compile error
const Foo = union(enum) {
    opt1: []const type,
    opt2: []const type,
};

pub fn main() !void {
    const foo1: Foo = Foo{ .opt1 = &.{} };
    std.debug.print("foo1: {any}\n", .{foo1});

    const foo2: Foo = Foo{ .opt2 = &.{} };
    std.debug.print("foo2: {any}\n", .{foo2});
}

As an investigation, I found the below definitions work, so it appears to be related to multiple fields of only type "[]type". I also tried this with a tagged union, and I get the same results.

// works
const Foo = union(enum) {
    opt1: []const i32,
    opt2: []const type,
};

// works
const Foo = union(enum) {
    opt1: []const type,
};

// works (work-around)
const Foo = union(enum(usize)) {
    opt1: []const type,
    opt2: []const type,
};

Expected Behavior

The union should be able to be compiled and used without error.

Activity

  1. added
    bugObserved behavior contradicts documented or intended behavior
    on Nov 16, 2025
  2. added this to the urgent milestone on Nov 16, 2025
  3. added
    enhancementSolving this issue will likely involve adding new logic or components to the codebase.
    standard libraryThis issue involves writing Zig code for the standard library.
    and removed
    bugObserved behavior contradicts documented or intended behavior
    on Jun 2, 2026
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

    enhancementSolving this issue will likely involve adding new logic or components to the codebase.standard libraryThis issue involves writing Zig code for the standard library.

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions