Commit 5f58956264

Bram <ogus.bram@gmail.com>
2024-06-01 21:04:02
std: Extended type checks for Thread startFn return type
1 parent f1b6f1a
Changed files (1)
lib
lib/std/Thread.zig
@@ -398,7 +398,7 @@ fn callFn(comptime f: anytype, args: anytype) switch (Impl) {
     else => unreachable,
 } {
     const default_value = if (Impl == PosixThreadImpl) null else 0;
-    const bad_fn_ret = "expected return type of startFn to be 'u8', 'noreturn', 'void', or '!void'";
+    const bad_fn_ret = "expected return type of startFn to be 'u8', 'noreturn', '!noreturn', 'void', or '!void'";
 
     switch (@typeInfo(@typeInfo(@TypeOf(f)).Fn.return_type.?)) {
         .NoReturn => {
@@ -422,18 +422,21 @@ fn callFn(comptime f: anytype, args: anytype) switch (Impl) {
             return default_value;
         },
         .ErrorUnion => |info| {
-            if (info.payload != void) {
-                @compileError(bad_fn_ret);
-            }
-
-            @call(.auto, f, args) catch |err| {
-                std.debug.print("error: {s}\n", .{@errorName(err)});
-                if (@errorReturnTrace()) |trace| {
-                    std.debug.dumpStackTrace(trace.*);
-                }
-            };
+            switch (info.payload) {
+                void, noreturn => {
+                    @call(.auto, f, args) catch |err| {
+                        std.debug.print("error: {s}\n", .{@errorName(err)});
+                        if (@errorReturnTrace()) |trace| {
+                            std.debug.dumpStackTrace(trace.*);
+                        }
+                    };
 
-            return default_value;
+                    return default_value;
+                },
+                else => {
+                    @compileError(bad_fn_ret);
+                },
+            }
         },
         else => {
             @compileError(bad_fn_ret);