compiler: implement @FieldType

Resolves: #21702
This commit is contained in:
mlugg
2024-10-17 10:19:14 +01:00
committed by Matthew Lugg
parent fffbb511db
commit 097766bba3
7 changed files with 103 additions and 1 deletions

View File

@@ -2159,3 +2159,27 @@ test "matching captures causes struct equivalence" {
comptime assert(@TypeOf(a) == @TypeOf(b));
try expect(a.x == b.x);
}
test "struct @FieldType" {
const S = struct {
a: u32,
b: f64,
c: *@This(),
};
comptime assert(@FieldType(S, "a") == u32);
comptime assert(@FieldType(S, "b") == f64);
comptime assert(@FieldType(S, "c") == *S);
}
test "extern struct @FieldType" {
const S = extern struct {
a: u32,
b: f64,
c: *@This(),
};
comptime assert(@FieldType(S, "a") == u32);
comptime assert(@FieldType(S, "b") == f64);
comptime assert(@FieldType(S, "c") == *S);
}