Sema: correct implementation of comptimeOnly for tuples

This makes formatted printing work when mixing comptime and runtime
fields.
This commit is contained in:
Andrew Kelley 2022-03-01 15:26:31 -07:00
parent f6aaab9406
commit 8878f085dc
3 changed files with 7 additions and 5 deletions

View File

@ -19585,8 +19585,9 @@ fn typeRequiresComptime(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) C
.tuple => {
const tuple = ty.castTag(.tuple).?.data;
for (tuple.types) |field_ty| {
if (try sema.typeRequiresComptime(block, src, field_ty)) {
for (tuple.types) |field_ty, i| {
const have_comptime_val = tuple.values[i].tag() != .unreachable_value;
if (!have_comptime_val and try sema.typeRequiresComptime(block, src, field_ty)) {
return true;
}
}

View File

@ -4050,8 +4050,9 @@ pub const Type = extern union {
.tuple => {
const tuple = ty.castTag(.tuple).?.data;
for (tuple.types) |field_ty| {
if (field_ty.comptimeOnly()) return true;
for (tuple.types) |field_ty, i| {
const have_comptime_val = tuple.values[i].tag() != .unreachable_value;
if (!have_comptime_val and field_ty.comptimeOnly()) return true;
}
return false;
},

View File

@ -45,7 +45,7 @@ test "tuple multiplication" {
comptime try S.doTheTest();
}
test "tuple concatenation" {
test "more tuple concatenation" {
if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
const T = struct {