-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
backend-self-hostedbugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior
Milestone
Description
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.
Metadata
Metadata
Assignees
Labels
backend-self-hostedbugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior