| ... | ... | @@ -247,26 +247,17 @@ fn add(a: i32, b: i32) i32 { |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | test "Type.ErrorSet" { |
| 250 | if (builtin.zig_backend == .stage1) return error.SkipZigTest; |
| 251 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO |
| 252 | |
| 250 | 253 | try testing.expect(@Type(.{ .ErrorSet = null }) == anyerror); |
| 251 | 254 | |
| 252 | 255 | // error sets don't compare equal so just check if they compile |
| 253 | | _ = @Type(@typeInfo(error{})); |
| 254 | | _ = @Type(@typeInfo(error{A})); |
| 255 | | _ = @Type(@typeInfo(error{ A, B, C })); |
| 256 | | _ = @Type(.{ |
| 257 | | .ErrorSet = &[_]Type.Error{ |
| 258 | | .{ .name = "A" }, |
| 259 | | .{ .name = "B" }, |
| 260 | | .{ .name = "C" }, |
| 261 | | }, |
| 262 | | }); |
| 263 | | _ = @Type(.{ |
| 264 | | .ErrorSet = &.{ |
| 265 | | .{ .name = "C" }, |
| 266 | | .{ .name = "B" }, |
| 267 | | .{ .name = "A" }, |
| 268 | | }, |
| 269 | | }); |
| 256 | inline for (.{ error{}, error{A}, error{ A, B, C } }) |T| { |
| 257 | const info = @typeInfo(T); |
| 258 | const T2 = @Type(info); |
| 259 | try testing.expect(T == T2); |
| 260 | } |
| 270 | 261 | } |
| 271 | 262 | |
| 272 | 263 | test "Type.Struct" { |
| ... | ... | @@ -517,3 +508,35 @@ test "Type.Union from regular enum" { |
| 517 | 508 | _ = T; |
| 518 | 509 | _ = @typeInfo(T).Union; |
| 519 | 510 | } |
| 511 | |
| 512 | test "Type.Fn" { |
| 513 | if (builtin.zig_backend == .stage1) return error.SkipZigTest; |
| 514 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO |
| 515 | |
| 516 | const some_opaque = opaque {}; |
| 517 | const some_ptr = *some_opaque; |
| 518 | const T = fn (c_int, some_ptr) callconv(.C) void; |
| 519 | |
| 520 | { |
| 521 | const fn_info = std.builtin.Type{ .Fn = .{ |
| 522 | .calling_convention = .C, |
| 523 | .alignment = 0, |
| 524 | .is_generic = false, |
| 525 | .is_var_args = false, |
| 526 | .return_type = void, |
| 527 | .args = &.{ |
| 528 | .{ .is_generic = false, .is_noalias = false, .arg_type = c_int }, |
| 529 | .{ .is_generic = false, .is_noalias = false, .arg_type = some_ptr }, |
| 530 | }, |
| 531 | } }; |
| 532 | |
| 533 | const fn_type = @Type(fn_info); |
| 534 | try std.testing.expectEqual(T, fn_type); |
| 535 | } |
| 536 | |
| 537 | { |
| 538 | const fn_info = @typeInfo(T); |
| 539 | const fn_type = @Type(fn_info); |
| 540 | try std.testing.expectEqual(T, fn_type); |
| 541 | } |
| 542 | } |