I’m trying to get the type of archetype at an index and ran into this error.
inline fn archetype(self: *Self, comptime archetype_type: ArchetypeType) *@TypeOf(self.archetypes[archetype_type.value()]) {
return &self.archetypes[archetype_type.value()];
}
inline fn typeOfArchetype(self: *Self, comptime archetype_type: ArchetypeType) type {
return @TypeOf(self.archetypes[archetype_type.value()]);
}
// @TypeOf(self.archetype(entity_archetype).*) ok
// self.typeOfArchetype(entity_archetype) error: unable to resolve comptime value
I was very surprised since both should be known at compile time, so to check things
I made a simpler example to check that the error was also there but it isn’t?
const Inner = struct {
u8,
u8,
};
const Outer = struct {
inner: Inner = .{ 1, 1 },
const Self = @This();
inline fn getPtr(self: *Self, comptime index: usize) *@TypeOf(self.inner[index]) {
return &self.inner[index];
}
inline fn getType(self: *Self, comptime index: usize) type {
return @TypeOf(self.inner[index]);
}
};
test "Does a simpler example compile" {
var outer: Outer = .{};
try std.testing.expect(@TypeOf(outer.getPtr(0).*) == outer.getType(0));
}
Here is an example where I get a compile error, both component_id and comptime_archetype are compile time known.
if (comptime self.typeOfArchetype(comptime_archetype).Components.bitset.isSet(component_id)) return error.EntityIsMissingComponent;
src/ecs.zig:630:38: error: unable to resolve comptime value
if (comptime self.typeOfArchetype(comptime_archetype).Components.bitset.isSet(component_id)) return error.EntityIsMissingComponent;
~~~~^~~~~~~~~~~~~~~~
src/ecs.zig:630:25: note: 'comptime' keyword forces comptime evaluation
if (comptime self.typeOfArchetype(comptime_archetype).Components.bitset.isSet(component_id)) return error.EntityIsMissingComponent;
What am I missing here?