diff --git a/src/stage1/ir.cpp b/src/stage1/ir.cpp index 3604f98ff55d4eb0b58609da28d13fb1a59e43f1..19242a5c42170472b8ec0e6f534cd673f1f636ab 100644 --- a/src/stage1/ir.cpp +++ b/src/stage1/ir.cpp @@ -16694,7 +16694,7 @@ static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira, { // We're now done inferring the type. container_type->data.structure.resolve_status = ResolveStatusUnstarted; - } else if (container_type->id == ZigTypeIdVector) { + } else if (container_type->id == ZigTypeIdVector || is_tuple(container_type)) { // OK } else { ir_add_error(ira, &instruction->base.base, diff --git a/test/behavior/tuple.zig b/test/behavior/tuple.zig index 0a32c664ddeabbd84826abf4b06c361b0f07f06b..29d44d582f160d28a17828f82be1f0cee231bf62 100644 --- a/test/behavior/tuple.zig +++ b/test/behavior/tuple.zig @@ -111,3 +111,39 @@ test "tuple initializer for var" { S.doTheTest(); comptime S.doTheTest(); } + +test "array-like initializer for tuple types" { + const T = @Type(std.builtin.TypeInfo{ + .Struct = std.builtin.TypeInfo.Struct{ + .is_tuple = true, + .layout = .Auto, + .decls = &[_]std.builtin.TypeInfo.Declaration{}, + .fields = &[_]std.builtin.TypeInfo.StructField{ + .{ + .name = "0", + .field_type = i32, + .default_value = @as(?i32, null), + .is_comptime = false, + .alignment = @alignOf(i32), + }, + .{ + .name = "1", + .field_type = u8, + .default_value = @as(?i32, null), + .is_comptime = false, + .alignment = @alignOf(i32), + }, + }, + }, + }); + const S = struct { + fn doTheTest() !void { + var obj: T = .{ -1234, 128 }; + try testing.expectEqual(@as(i32, -1234), obj[0]); + try testing.expectEqual(@as(u8, 128), obj[1]); + } + }; + + try S.doTheTest(); + comptime try S.doTheTest(); +}