Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
AnneKitsune opened this issue May 5, 2024 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@AnneKitsune
Copy link

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 AnneKitsune added the bug Observed behavior contradicts documented or intended behavior label May 5, 2024
@Pyrolistical
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

2 participants