Functions f and g are the same, except that g takes an unused parameter. f can be evaluated at comptime, but g can be evaluated at comptime only if its argument is comptime. Do you think g should be comptime-evaluatable with any (runtime, comptime) argument?
src\main.zig:14:20: error: unable to resolve comptime value
_ = comptime g(v);
^
src\main.zig:14:20: note: argument to function being called at comptime must be comptime-known
Making ginline doesn’t help.
I want to create structs that follow the same (comptime) interface, but give some of the functions of some of the structs an ability to be comptime-evaluatable. A silly example would be
I’ve run into this myself. Zig is currently ‘pessimistic’ about passing runtime-only values into a comptime-only context: it simply doesn’t allow it.
That’s understandable, but I would love to see that become optimistic: for example, a comptime-only function can be passed a runtime-known variable, as long as it’s only used for its type information, or not used at all (there’s little point in that but it would follow from the premise).
But currently that isn’t how it works: runtime-known information can’t cross the comptime boundary at all, the error is at that boundary rather than on a line of code which tries to make comptime use of the runtime information.
Zig will sometimes do this anyway, but it isn’t always clear when: marking the function call comptime will give you a compile error if the call can’t be completed at comptime, but the converse isn’t true: function calls without the comptime tag may or may not become part of the runtime code. It’s a reliable way to check if you’re not sure.