authorgravatar for k4@noreply.codeberg.orgK4 <k4@noreply.codeberg.org> 2026-04-12 17:14:06+03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-04-16 01:04:41+02:00
logbf402649411f8ddbfab94dbab6088215d67e0e00
tree3c4bd70ee9f4e6626dd7265ac2e447fb08dfb9ad
parenta999fc9059cf4daad462294a08874cc1c2d402af

add test for comptime-only functions


1 files changed, 12 insertions(+), 0 deletions(-)

test/behavior/fn.zig+12
......@@ -770,3 +770,15 @@ test "return undefined pointer from function, directly and by expired local" {
770770 const bad_ptr_2 = S.returnStackPointer();
771771 _ = bad_ptr_2; // dereferencing this would be illegal behavior
772772}
773
774test "a function that works at comptime but not runtime" {
775 const a = comptime testComptimeOnlyFn(1, 1);
776 try expect(a[0] == 1);
777 try expect(a[1] == 2);
778}
779
780fn testComptimeOnlyFn(x: u32, y: u32) [2]u8 {
781 const xa: [x]u8 = .{1};
782 const ya: [y]u8 = .{2};
783 return xa ++ ya;
784}