-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Unexpected type dependency loop when declaring a function pointer to a function that returns its own type. #18664
Comments
Duplicate #12325 likely |
I get this running it
|
With the latest master binaries produced on 2024-01-25, zig version "0.12.0-dev.2341+92211135f" I am still getting "dependency loop detected". |
Related dependency loop issues #16932 and #131 smaller test case: const StateFn = *const fn () ?StateFn;
fn done() ?StateFn {
return null;
}
test {
_ = done();
} zig 0.12.0-dev.2928+6fddc9cd3 output:
|
I should note you can work around this by wrapping this data in a struct: const State = struct {
evalFn: *const fn () ?State,
}; The error here happens because we only have lazy resolution (which permits recursive definitions) for structs, unions, enums, and opaques. It's not exactly a duplicate, but is heavily related to #12325. |
Thank you very much @mlugg for the workaround |
Zig Version
0.11.0, 0.12.0-dev.2327+b0c8a3f31
Steps to Reproduce and Observed Behavior
Example program:
Expected Behavior
Expecting zig compiler to accept the function pointer declaration of a function that returns itself.
Such declarations are useful in lexer/scanner trampolines.
Example
golang
code: https://cs.opensource.google/go/go/+/master:src/text/template/parse/lex.go;l=110The text was updated successfully, but these errors were encountered: