Skip to content

Aggregate initializers should allow initializing comptime fields, verifying equality #11162

@topolarity

Description

@topolarity

Zig Version

0.10.0-dev.1246+5fbae9cd6

Steps to Reproduce

cc @ifreund and @mitchellh , who provided these test cases

test {
    const T = @TypeOf(.{ @as(i32, 0), @as(u8, 123) });
    var a: T = .{-1234, 0};
    try testing.expectEqual(@as(i32, 0), a[0]);
    try testing.expectEqual(@as(u8, 123), a[1]);
}

test {
    const T = struct {
        comptime x: i32 = 0,
        comptime y: u8 = 123,
    };
    var a: T = .{.x = -1234, .y = 0};
    try testing.expectEqual(@as(i32, 0), a.x);
    try testing.expectEqual(@as(u8, 123), a.y);
}

Expected Behavior

Test should fail - the provided field does not match the value of the comptime field.

Equality should be checked for the init value of comptime fields, in both structs and arrays.

Actual Behavior

The test passes on stage1.

It fails on stage2 due to #11159, but once that bug is fixed it will incorrectly pass.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions