authorgravatar for 59504965+InKryption@users.noreply.github.comInKryption <59504965+InKryption@users.noreply.github.com> 2021-10-28 16:59:54+01:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-10-29 20:02:25+00:00
log83a4bb6e6957325b744a08e16cab6b2a4a045f3e
tree8c1fa68583c19c11ed2bf2e986364524f95c5e13
parenteeb8629bea90b931a65559886c272fe7aad9211d

Make `std.meta.trait.isContainer` true for opaques

Makes `std.meta.trait.hasFn` work as expected for opaque types with function declarations. Alternative is to add clause directly to `std.meta.trait.hasFn` to account for opaque types.

1 files changed, 3 insertions(+), 1 deletions(-)

lib/std/meta/trait.zig+3-1
......@@ -354,7 +354,7 @@ test "std.meta.trait.isConstPtr" {
354354
355355pub fn isContainer(comptime T: type) bool {
356356 return switch (@typeInfo(T)) {
357 .Struct, .Union, .Enum => true,
357 .Struct, .Union, .Enum, .Opaque => true,
358358 else => false,
359359 };
360360}
......@@ -368,10 +368,12 @@ test "std.meta.trait.isContainer" {
368368 A,
369369 B,
370370 };
371 const TestOpaque = opaque {};
371372
372373 try testing.expect(isContainer(TestStruct));
373374 try testing.expect(isContainer(TestUnion));
374375 try testing.expect(isContainer(TestEnum));
376 try testing.expect(isContainer(TestOpaque));
375377 try testing.expect(!isContainer(u8));
376378}
377379