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.
This commit is contained in:
InKryption 2021-10-28 16:59:54 +01:00 committed by Veikka Tuominen
parent eeb8629bea
commit 83a4bb6e69

View File

@ -354,7 +354,7 @@ test "std.meta.trait.isConstPtr" {
pub fn isContainer(comptime T: type) bool {
return switch (@typeInfo(T)) {
.Struct, .Union, .Enum => true,
.Struct, .Union, .Enum, .Opaque => true,
else => false,
};
}
@ -368,10 +368,12 @@ test "std.meta.trait.isContainer" {
A,
B,
};
const TestOpaque = opaque {};
try testing.expect(isContainer(TestStruct));
try testing.expect(isContainer(TestUnion));
try testing.expect(isContainer(TestEnum));
try testing.expect(isContainer(TestOpaque));
try testing.expect(!isContainer(u8));
}