authorgravatar for ogus.bram@gmail.comBram <ogus.bram@gmail.com> 2024-06-01 15:04:02-04:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-06-23 04:35:00+01:00
log5f589562646b972e4f177d60c7da37e872991d29
treecf33366a36e188ba2345894c43ee362918aff428
parentf1b6f1aeb38452fce2c1185326556566cacee2ca

std: Extended type checks for Thread startFn return type


1 files changed, 15 insertions(+), 12 deletions(-)

lib/std/Thread.zig+15-12
...@@ -398,7 +398,7 @@ fn callFn(comptime f: anytype, args: anytype) switch (Impl) {...@@ -398,7 +398,7 @@ fn callFn(comptime f: anytype, args: anytype) switch (Impl) {
398 else => unreachable,398 else => unreachable,
399} {399} {
400 const default_value = if (Impl == PosixThreadImpl) null else 0;400 const default_value = if (Impl == PosixThreadImpl) null else 0;
401 const bad_fn_ret = "expected return type of startFn to be 'u8', 'noreturn', 'void', or '!void'";401 const bad_fn_ret = "expected return type of startFn to be 'u8', 'noreturn', '!noreturn', 'void', or '!void'";
402402
403 switch (@typeInfo(@typeInfo(@TypeOf(f)).Fn.return_type.?)) {403 switch (@typeInfo(@typeInfo(@TypeOf(f)).Fn.return_type.?)) {
404 .NoReturn => {404 .NoReturn => {
...@@ -422,18 +422,21 @@ fn callFn(comptime f: anytype, args: anytype) switch (Impl) {...@@ -422,18 +422,21 @@ fn callFn(comptime f: anytype, args: anytype) switch (Impl) {
422 return default_value;422 return default_value;
423 },423 },
424 .ErrorUnion => |info| {424 .ErrorUnion => |info| {
425 if (info.payload != void) {425 switch (info.payload) {
426 @compileError(bad_fn_ret);426 void, noreturn => {
427 }427 @call(.auto, f, args) catch |err| {
428428 std.debug.print("error: {s}\n", .{@errorName(err)});
429 @call(.auto, f, args) catch |err| {429 if (@errorReturnTrace()) |trace| {
430 std.debug.print("error: {s}\n", .{@errorName(err)});430 std.debug.dumpStackTrace(trace.*);
431 if (@errorReturnTrace()) |trace| {431 }
432 std.debug.dumpStackTrace(trace.*);432 };
433 }
434 };
435433
436 return default_value;434 return default_value;
435 },
436 else => {
437 @compileError(bad_fn_ret);
438 },
439 }
437 },440 },
438 else => {441 else => {
439 @compileError(bad_fn_ret);442 @compileError(bad_fn_ret);