That is actually true: if what you assign to the const variable is comptime known, then so is the const variable. In your example, for the expression to be comptime known you need to either prefix it with comptime
or make the function inline
, as you noticed.
Somewhat related, if you look at the implementation of fieldNames
, you’ll see this:
const final = names;
break :blk &final;
…which copies the value from the comptime world to a const, whose pointer is returned at runtime (unless the callsite is comptime ofc). This is described here: https://ziggit.dev/t/comptime-mutable-memory-changes/3702