| ... | @@ -1149,3 +1149,27 @@ test "isError" { | ... | @@ -1149,3 +1149,27 @@ test "isError" { |
| 1149 | try std.testing.expect(isError(math.absInt(@as(i8, -128)))); | 1149 | try std.testing.expect(isError(math.absInt(@as(i8, -128)))); |
| 1150 | try std.testing.expect(!isError(math.absInt(@as(i8, -127)))); | 1150 | try std.testing.expect(!isError(math.absInt(@as(i8, -127)))); |
| 1151 | } | 1151 | } |
| | 1152 | |
| | 1153 | /// This function returns a function pointer for a given function signature. |
| | 1154 | /// It's a helper to make code compatible to both stage1 and stage2. |
| | 1155 | /// |
| | 1156 | /// **WARNING:** This function is deprecated and will be removed together with stage1. |
| | 1157 | pub fn FnPtr(comptime Fn: type) type { |
| | 1158 | return if (@import("builtin").zig_backend != .stage1) |
| | 1159 | *const Fn |
| | 1160 | else |
| | 1161 | Fn; |
| | 1162 | } |
| | 1163 | |
| | 1164 | test "FnPtr" { |
| | 1165 | var func: FnPtr(fn () i64) = undefined; |
| | 1166 | |
| | 1167 | // verify that we can perform runtime exchange |
| | 1168 | // and not have a function body in stage2: |
| | 1169 | |
| | 1170 | func = std.time.timestamp; |
| | 1171 | _ = func(); |
| | 1172 | |
| | 1173 | func = std.time.milliTimestamp; |
| | 1174 | _ = func(); |
| | 1175 | } |