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" {...@@ -354,7 +354,7 @@ test "std.meta.trait.isConstPtr" {
354354
355pub fn isContainer(comptime T: type) bool {355pub fn isContainer(comptime T: type) bool {
356 return switch (@typeInfo(T)) {356 return switch (@typeInfo(T)) {
357 .Struct, .Union, .Enum => true,357 .Struct, .Union, .Enum, .Opaque => true,
358 else => false,358 else => false,
359 };359 };
360}360}
...@@ -368,10 +368,12 @@ test "std.meta.trait.isContainer" {...@@ -368,10 +368,12 @@ test "std.meta.trait.isContainer" {
368 A,368 A,
369 B,369 B,
370 };370 };
371 const TestOpaque = opaque {};
371372
372 try testing.expect(isContainer(TestStruct));373 try testing.expect(isContainer(TestStruct));
373 try testing.expect(isContainer(TestUnion));374 try testing.expect(isContainer(TestUnion));
374 try testing.expect(isContainer(TestEnum));375 try testing.expect(isContainer(TestEnum));
376 try testing.expect(isContainer(TestOpaque));
375 try testing.expect(!isContainer(u8));377 try testing.expect(!isContainer(u8));
376}378}
377379