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

Improve error for a function declared inside another function #17440

Open
Atomk opened this issue Oct 8, 2023 · 0 comments
Open

Improve error for a function declared inside another function #17440

Atomk opened this issue Oct 8, 2023 · 0 comments
Labels
error message This issue points out an error message that is unhelpful and should be improved.
Milestone

Comments

@Atomk
Copy link
Contributor

Atomk commented Oct 8, 2023

Zig Version

0.11.0

Steps to Reproduce and Observed Output

Build a file containing the following code:

pub fn main() void {
    fn foo() void { }
}

The error:

test.zig:2:22: error: expected ';' after statement
    fn foo() void { }
                     ^

After adding the semicolon as suggested:

test.zig:2:8: error: function type cannot have a name
    fn foo() void { };
       ^~~

After removing the name as suggested:

test.zig:2:16: error: type 'fn() void' does not support array initialization syntax
    fn () void { };
    ~~~~~~~~~~~^~~
referenced by:
    callMain: zig-windows-x86_64-0.11.0\lib\std\start.zig:564:17
    initEventLoopAndCallMain: zig-windows-x86_64-0.11.0\lib\std\start.zig:508:34
    remaining reference traces hidden; use '-freference-trace' to see all reference traces

Expected Output

Something similar to:

test.zig:2:5: error: cannot create a function inside a function
    fn foo() void { };
    ^~~~~~~
@Atomk Atomk added the error message This issue points out an error message that is unhelpful and should be improved. label Oct 8, 2023
@Vexu Vexu added this to the 0.13.0 milestone Oct 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error message This issue points out an error message that is unhelpful and should be improved.
Projects
None yet
Development

No branches or pull requests

2 participants