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...@@ -19585,8 +19585,9 @@ fn typeRequiresComptime(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) C
1958519585
19586 .tuple => {19586 .tuple => {
19587 const tuple = ty.castTag(.tuple).?.data;19587 const tuple = ty.castTag(.tuple).?.data;
19588 for (tuple.types) |field_ty| {19588 for (tuple.types) |field_ty, i| {
19589 if (try sema.typeRequiresComptime(block, src, field_ty)) {19589 const have_comptime_val = tuple.values[i].tag() != .unreachable_value;
19590 if (!have_comptime_val and try sema.typeRequiresComptime(block, src, field_ty)) {
19590 return true;19591 return true;
19591 }19592 }
19592 }19593 }
src/type.zig+3-2
...@@ -4050,8 +4050,9 @@ pub const Type = extern union {...@@ -4050,8 +4050,9 @@ pub const Type = extern union {
40504050
4051 .tuple => {4051 .tuple => {
4052 const tuple = ty.castTag(.tuple).?.data;4052 const tuple = ty.castTag(.tuple).?.data;
4053 for (tuple.types) |field_ty| {4053 for (tuple.types) |field_ty, i| {
4054 if (field_ty.comptimeOnly()) return true;4054 const have_comptime_val = tuple.values[i].tag() != .unreachable_value;
4055 if (!have_comptime_val and field_ty.comptimeOnly()) return true;
4055 }4056 }
4056 return false;4057 return false;
4057 },4058 },
test/behavior/tuple.zig+1-1
...@@ -45,7 +45,7 @@ test "tuple multiplication" {...@@ -45,7 +45,7 @@ test "tuple multiplication" {
45 comptime try S.doTheTest();45 comptime try S.doTheTest();
46}46}
4747
48test "tuple concatenation" {48test "more tuple concatenation" {
49 if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO49 if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
5050
51 const T = struct {51 const T = struct {