Why does this work:
const value = getValue(bool);
//def
fn getValue(comptime T: type) T {
switch (@typeInfo(T)) {
.bool => return true,
.int => return 4,
else => return null,
}
}```
but this doesn't
```c
const myUnion = MyUnion{ .bool = true }
const value = getUnionValue(bool, myUnion);
//def
const MyUnion = union(enum) {
bool: bool,
int: i32,
};
fn getUnionValue(comptime T: type, myUnion: MyUnion) T {
switch (myUnion) {
.bool => return true,
.int => return 4,
}
}```
The compiler yells at me for having a possible return that's not a bool with the union, but it has no problems with non bool returns when just using a type.