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