zig icon indicating copy to clipboard operation
zig copied to clipboard

Unable to evaluate comptime expression, operation is runtime due to this operand. However, it is entirely compile time.

Open AnneKitsune opened this issue 1 year ago • 1 comments

Zig Version

0.12.0

Steps to Reproduce and Observed Behavior

Code:

const std = @import("std");

const things = .{
    a // Compiles fine if I comment this, but not if I uncomment
} ++ gen(b);

pub fn main() !void {
    _ = things;
}

pub fn a() void {}
pub fn b(u: u32) void {_ = u;}

fn gen(comptime func: anytype) struct{@TypeOf(func)} {
    return .{
        func,
    };
}

output:

anne@umaru:/tmp/a/ > zig build run
run
└─ run a
   └─ zig build-exe a Debug native 1 errors
src/main.zig:5:3: error: unable to evaluate comptime expression
} ++ gen(b);
  ^~~~~~~~~
src/main.zig:5:9: note: operation is runtime due to this operand
} ++ gen(b);
     ~~~^~~
referenced by:
    main: src/main.zig:8:9
    callMain: /nix/store/ymq0w17q7vy4xf2phd74pqhsyfdmam3s-zig-0.12.0/lib/zig/std/start.zig:511:32
    remaining reference traces hidden; use '-freference-trace' to see all reference traces

Expected Behavior

Code compiling correctly.

AnneKitsune avatar May 05 '24 17:05 AnneKitsune

I think you need a comptime infront of gen(b)

Pyrolistical avatar May 06 '24 06:05 Pyrolistical