Skip to content

A bit unclear error message in case of nested ifs without braces #15842

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

Open
dee0xeed opened this issue May 24, 2023 · 2 comments
Open

A bit unclear error message in case of nested ifs without braces #15842

dee0xeed opened this issue May 24, 2023 · 2 comments
Labels
error message This issue points out an error message that is unhelpful and should be improved.
Milestone

Comments

@dee0xeed
Copy link

Zig Version

0.10.1

Steps to Reproduce and Observed Output

Compile this:

// ifif.zig
pub fn main() void {
    var a: u32 = 7;
    var b: u32 = 8;
    var c: u32 = 9;

    if (a < b)
        if (b < c)
            a += 1;
}

Error message:

$ /opt/zig-0.10.1/zig build-exe ifif.zig 
ifif.zig:8:9: error: invalid left-hand side to assignment
        if (b < c)
        ^~

Expected Output

This can be fixed by putting braces for first if.
Maybe, error message should tell exactly about missing braces?..

@dee0xeed dee0xeed added the error message This issue points out an error message that is unhelpful and should be improved. label May 24, 2023
@infdahai
Copy link

Yeah, you're right and the error message needs to be more friendly.

The doc https://ziglang.org/documentation/master/#if shows we need braces.

@Vexu
Copy link
Member

Vexu commented May 24, 2023

Related #11805

@Vexu Vexu added this to the 0.13.0 milestone May 24, 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

3 participants