authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-01 15:26:31-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-01 15:26:31-07:00
log8878f085dccaf9efe89a04b458205fddc215e095
treebe49e3d222c1e58d4f962f155d24a197c8bd4778
parentf6aaab9406807305c2b48fcd742449c9e91f1851

Sema: correct implementation of comptimeOnly for tuples

This makes formatted printing work when mixing comptime and runtime fields.

3 files changed, 7 insertions(+), 5 deletions(-)

src/Sema.zig+3-2
......@@ -19585,8 +19585,9 @@ fn typeRequiresComptime(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) C
1958519585
1958619586 .tuple => {
1958719587 const tuple = ty.castTag(.tuple).?.data;
19588 for (tuple.types) |field_ty| {
19589 if (try sema.typeRequiresComptime(block, src, field_ty)) {
19588 for (tuple.types) |field_ty, i| {
19589 const have_comptime_val = tuple.values[i].tag() != .unreachable_value;
19590 if (!have_comptime_val and try sema.typeRequiresComptime(block, src, field_ty)) {
1959019591 return true;
1959119592 }
1959219593 }
src/type.zig+3-2
......@@ -4050,8 +4050,9 @@ pub const Type = extern union {
40504050
40514051 .tuple => {
40524052 const tuple = ty.castTag(.tuple).?.data;
4053 for (tuple.types) |field_ty| {
4054 if (field_ty.comptimeOnly()) return true;
4053 for (tuple.types) |field_ty, i| {
4054 const have_comptime_val = tuple.values[i].tag() != .unreachable_value;
4055 if (!have_comptime_val and field_ty.comptimeOnly()) return true;
40554056 }
40564057 return false;
40574058 },
test/behavior/tuple.zig+1-1
......@@ -45,7 +45,7 @@ test "tuple multiplication" {
4545 comptime try S.doTheTest();
4646}
4747
48test "tuple concatenation" {
48test "more tuple concatenation" {
4949 if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
5050
5151 const T = struct {