| ... | @@ -497,21 +497,19 @@ fn mainWithoutEnv(c_argc: c_int, c_argv: [*][*:0]c_char) callconv(.C) c_int { | ... | @@ -497,21 +497,19 @@ fn mainWithoutEnv(c_argc: c_int, c_argv: [*][*:0]c_char) callconv(.C) c_int { |
| 497 | const bad_main_ret = "expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'"; | 497 | const bad_main_ret = "expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'"; |
| 498 | | 498 | |
| 499 | pub inline fn callMain() u8 { | 499 | pub inline fn callMain() u8 { |
| 500 | switch (@typeInfo(@typeInfo(@TypeOf(root.main)).Fn.return_type.?)) { | 500 | const ReturnType = @typeInfo(@TypeOf(root.main)).Fn.return_type.?; |
| 501 | .NoReturn => { | 501 | |
| 502 | root.main(); | 502 | switch (ReturnType) { |
| 503 | }, | 503 | void => { |
| 504 | .Void => { | | |
| 505 | root.main(); | 504 | root.main(); |
| 506 | return 0; | 505 | return 0; |
| 507 | }, | 506 | }, |
| 508 | .Int => |info| { | 507 | noreturn, u8 => { |
| 509 | if (info.bits != 8 or info.signedness == .signed) { | | |
| 510 | @compileError(bad_main_ret); | | |
| 511 | } | | |
| 512 | return root.main(); | 508 | return root.main(); |
| 513 | }, | 509 | }, |
| 514 | .ErrorUnion => { | 510 | else => { |
| | 511 | if (@typeInfo(ReturnType) != .ErrorUnion) @compileError(bad_main_ret); |
| | 512 | |
| 515 | const result = root.main() catch |err| { | 513 | const result = root.main() catch |err| { |
| 516 | std.log.err("{s}", .{@errorName(err)}); | 514 | std.log.err("{s}", .{@errorName(err)}); |
| 517 | if (@errorReturnTrace()) |trace| { | 515 | if (@errorReturnTrace()) |trace| { |
| ... | @@ -519,18 +517,13 @@ pub inline fn callMain() u8 { | ... | @@ -519,18 +517,13 @@ pub inline fn callMain() u8 { |
| 519 | } | 517 | } |
| 520 | return 1; | 518 | return 1; |
| 521 | }; | 519 | }; |
| 522 | switch (@typeInfo(@TypeOf(result))) { | 520 | |
| 523 | .Void => return 0, | 521 | return switch (@TypeOf(result)) { |
| 524 | .Int => |info| { | 522 | void => 0, |
| 525 | if (info.bits != 8 or info.signedness == .signed) { | 523 | u8 => result, |
| 526 | @compileError(bad_main_ret); | | |
| 527 | } | | |
| 528 | return result; | | |
| 529 | }, | | |
| 530 | else => @compileError(bad_main_ret), | 524 | else => @compileError(bad_main_ret), |
| 531 | } | 525 | }; |
| 532 | }, | 526 | }, |
| 533 | else => @compileError(bad_main_ret), | | |
| 534 | } | 527 | } |
| 535 | } | 528 | } |
| 536 | | 529 | |