Skip to content

extern struct created at comptime results in "unable to evaluate comptime expression" #15616

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

Closed
Jarred-Sumner opened this issue May 8, 2023 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@Jarred-Sumner
Copy link
Contributor

Zig Version

0.11.0-dev.2571+31738de28

Steps to Reproduce and Observed Behavior

Code:

const std = @import("std");

const ___tracy_source_location_data = extern struct {
    name: ?[*:0]const u8,
    function: [*:0]const u8,
    file: [*:0]const u8,
    line: u32,
    color: u32,
};

pub inline fn traceNamed(comptime src: std.builtin.SourceLocation, comptime name: [*:0]const u8) Ctx {
    const holder = struct {
        pub const data: ___tracy_source_location_data = ___tracy_source_location_data{
            .name = name,
            .function = src.fn_name.ptr,
            .file = src.file.ptr,
            .line = src.line,
            .color = 0,
        };
    };
    return ___tracy_emit_zone_begin(&holder.data, 1);
}

pub fn main() anyerror!void {
    const ctx = traceNamed(@src(), "main");
    _ = ctx.id;
}

extern fn ___tracy_emit_zone_begin(data: *const ___tracy_source_location_data, depth: u32) Ctx;

pub const Ctx = extern struct {
    id: u64 = 0,
};
zig build-exe ./repro.zig

Message:

repro.zig:13:86: error: unable to evaluate comptime expression
        pub const data: ___tracy_source_location_data = ___tracy_source_location_data{
                                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
referenced by:
    traceNamed: /Users/jarred/Desktop/repro.zig:21:44
    main: /Users/jarred/Desktop/repro.zig:25:17
    remaining

Expected Behavior

No error

@Jarred-Sumner Jarred-Sumner added the bug Observed behavior contradicts documented or intended behavior label May 8, 2023
@leecannon
Copy link
Contributor

This is caused by @src().line not being compile time known. #13315 (comment)

@Vexu Vexu closed this as completed May 8, 2023
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

3 participants