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

Dependency loop caused by explicit mentioning of function pointer type #16932

Open
copygirl opened this issue Aug 23, 2023 · 2 comments
Open
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@copygirl
Copy link

Zig Version

0.11.0

Steps to Reproduce and Observed Behavior

With the following zig code:

const ecs_iter_next_action_t = ?*const fn (*ecs_iter_t) void;
const ecs_iter_t = struct { next: ecs_iter_next_action_t };

test {
    _ = ecs_iter_next_action_t;
}

pub fn main() void {
    var it = ecs_iter_t{ .next = &next_action };
    it.next.?(&it);
}

fn next_action(it: *ecs_iter_t) void {
    @import("std").debug.print("{any}\n", .{it});
}

Running zig run yields the expected output:

main.ecs_iter_t{ .next = fn(*main.ecs_iter_t) void@220780 }

However when running zig test (here with -freference-trace), I get a dependency loop error:

main.zig:1:1: error: dependency loop detected
const ecs_iter_next_action_t = ?*const fn (*ecs_iter_t) void;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
    ecs_iter_t: main.zig:2:20
    ecs_iter_next_action_t: main.zig:1:45
    ecs_iter_t: main.zig:2:35

Expected Behavior

No dependency loop.

@copygirl copygirl added the bug Observed behavior contradicts documented or intended behavior label Aug 23, 2023
@copygirl
Copy link
Author

copygirl commented Aug 23, 2023

If I change the main function to the following, the dependency loop error also occurs for zig run.

pub fn main() void {
    var next: ecs_iter_next_action_t = &next_action;
    var it = ecs_iter_t{ .next = next };
    it.next.?(&it);
}

However, only if the type is actually specified, change the second line to this and it's fine again:

var next = &next_action;

@copygirl copygirl changed the title Dependency loop caused by test declaration Dependency loop caused by explicit mentioning of function pointer type Aug 23, 2023
@andrewrk andrewrk added this to the 0.11.1 milestone Aug 25, 2023
@copygirl
Copy link
Author

copygirl commented Sep 2, 2023

I also have a larger codebase where I wrap some C code where this issue occurs. Sometimes. Seemingly randomly. Practically the same code compiled earlier and now that I made some seemingly unrelated changes, the dependency loop error is back.

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