Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -683,4 +683,26 @@ pub fn build(b: *std.Build) void {
b.installArtifact(tests);

test_step.dependOn(&b.addRunArtifact(tests).step);

const comptime_test_step = b.step("test-comptime", "Run zflecs comptime tests");
const comptime_tests_module = b.createModule(.{
.root_source_file = b.path("src/comptime_error_tests.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
comptime_tests_module.addOptions("build-options", options);
comptime_tests_module.addIncludePath(b.path("libs/flecs"));
comptime_tests_module.linkLibrary(lib);

const comptime_tests = b.addTest(.{
.name = "zflecs-comptime-tests",
.root_module = comptime_tests_module,
});
comptime_tests.expect_errors = .{
.contains = "Tags are not allowed in system functions.",
};
b.installArtifact(comptime_tests);

comptime_test_step.dependOn(&comptime_tests.step);
}
31 changes: 31 additions & 0 deletions src/comptime_error_tests.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const std = @import("std");
const ecs = @import("zflecs.zig");
const builtin = @import("builtin");

const print = std.log.info;

const Position = struct { x: f32, y: f32 };
const Velocity = struct { x: f32, y: f32 };

const Apples = struct {};

fn move_apples_system(positions: []Position, velocities: []const Velocity, _: []const Apples) void {
for (positions, velocities) |*p, v| {
p.x += v.x;
p.y += v.y;
}
}

test "zflecs.block_tags_systemcomptime" {
print("\n", .{});

const world = ecs.init();
defer _ = ecs.fini(world);

ecs.COMPONENT(world, Position);
ecs.COMPONENT(world, Velocity);

ecs.TAG(world, Apples);

_ = ecs.ADD_SYSTEM(world, "move system", ecs.OnUpdate, move_apples_system);
}
7 changes: 7 additions & 0 deletions src/zflecs.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3006,6 +3006,13 @@ pub fn SYSTEM_DESC(comptime fn_system: anytype) system_desc_t {
const param_type_info = @typeInfo(p.type.?).pointer;
const inout = if (param_type_info.is_const) .In else .InOut;
system_desc.query.terms[i - start_index] = .{ .id = id(param_type_info.child), .inout = inout };

const child_info = @typeInfo(param_type_info.child).@"struct";
if (child_info.fields.len == 0) {
@compileError(
"Tags are not allowed in system functions.",
);
}
}

return system_desc;
Expand Down