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

False dependency loop with function pointer #14353

Open
mitchellh opened this issue Jan 17, 2023 · 7 comments
Open

False dependency loop with function pointer #14353

mitchellh opened this issue Jan 17, 2023 · 7 comments
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@mitchellh
Copy link
Sponsor Contributor

mitchellh commented Jan 17, 2023

Zig Version

0.11.0-dev.1329+37424fd11

Steps to Reproduce and Observed Behavior

zig test test.zig:

pub const A = struct {
    field: B = undefined,
};

pub const B = struct {
    field: *const fn (*A) void,
};

test {
    var a: usize = @sizeOf(B);
    _ = a;
}

Some notes:

  • Must be runtime, comptime works fine (var vs const)
  • Must be function pointer, regular pointer to *A works fine
  • Must have initializer on A's field

Expected Behavior

No error.

@mitchellh mitchellh added the bug Observed behavior contradicts documented or intended behavior label Jan 17, 2023
@mitchellh
Copy link
Sponsor Contributor Author

Maybe a dup of the following, but they seemed slightly different:

#14147
#12325

@nektro
Copy link
Contributor

nektro commented Jan 17, 2023

michal-z's reduction in 12325 is the same as yours

@mitchellh
Copy link
Sponsor Contributor Author

Yeah, perhaps it is. There are some weird properties of mine I wasn't sure about and the shape didn't feel identical. For example, if you get rid of the initializer = undefined in mine, it works.

@nektro
Copy link
Contributor

nektro commented Jan 17, 2023

if you remove the = undefined and change the test to @sizeOf(A) does it crash? i think that might be another difference between the two

@mitchellh
Copy link
Sponsor Contributor Author

if you remove the = undefined and change the test to @sizeOf(A) does it crash? i think that might be another difference between the two

That also works fine (doesn't produce compiler error).

@perillo
Copy link
Contributor

perillo commented Jan 30, 2024

@mitchellh It seems the bug has been fixed, since with 0.12.0-dev.2341+92211135 the test runs correctly.

@Vexu
Copy link
Member

Vexu commented Jan 30, 2024

It triggers an assertion failure with a debug build.

@andrewrk andrewrk modified the milestones: 0.12.0, 0.13.0 Jan 31, 2024
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

5 participants