Zig Version
0.12.0-dev.2711+f995c1b08
Steps to Reproduce and Observed Behavior
Extracted from #18808 (comment)
However... when I tried this example below I was actually surprised:
conststd=@import("std");
externfnside_effect(*i32) void;
inlinefnexample(runtime_known: *i32, comptimex: bool) type {
if (x) {
returnf32;
} else {
side_effect(runtime_known);
}
}
test"pass runtime param, receive comptime value" {
constptr=trystd.testing.allocator.create(i32);
deferstd.testing.allocator.destroy(ptr);
constT=example(ptr, true);
trystd.testing.expect(T==f32);
}test.zig:17:23: error: unable to resolve comptime value
const T = example(ptr, true);
^~~
test.zig:17:23: note: argument to function being called at comptime must be comptime-known
test.zig:5:58: note: expression is evaluated at comptime because the function returns a comptime-only type 'type'
inline fn example(runtime_known: *i32, comptime x: bool) type {
^~~~
test.zig:5:58: note: types are not available at runtime
inline fn example(runtime_known: *i32, comptime x: bool) type {
^~~~
The problem here is that the return type forces the function call to be comptime, when we actually just wanted it to be inline. I will open a bug report for this.
I couldn't find a bug report.
Another quick test that should succeed:
conststd=@import("std");
test"inline function with comptime-known comptime-only return type called at runtime" {
constS=struct {
inlinefnfoo(x: *i32, y: *consti32) type {
x.*=y.*;
returnf32;
}
};
vara: i32=0;
constb: i32=111;
constT=S.foo(&a, &b);
trystd.testing.expectEqual(111, a);
trystd.testing.expectEqual(f32, T);
}Expected Behavior
All tests pass.
Zig Version
0.12.0-dev.2711+f995c1b08
Steps to Reproduce and Observed Behavior
Extracted from #18808 (comment)
I couldn't find a bug report.
Another quick test that should succeed:
Expected Behavior
All tests pass.