Commit 8878f085dc

Andrew Kelley <andrew@ziglang.org>
2022-03-01 23:26:31
Sema: correct implementation of comptimeOnly for tuples
This makes formatted printing work when mixing comptime and runtime fields.
1 parent f6aaab9
Changed files (3)
src
test
behavior
src/Sema.zig
@@ -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;
                 }
             }
src/type.zig
@@ -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;
             },
test/behavior/tuple.zig
@@ -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 {