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 message when incorrectly using the || operator instead of or #22200

Open
MaddyGuthridge opened this issue Dec 10, 2024 · 1 comment
Labels
error message This issue points out an error message that is unhelpful and should be improved.
Milestone

Comments

@MaddyGuthridge
Copy link

Zig Version

0.13.0

Steps to Reproduce and Observed Output

In the following code, I incorrectly used || instead of or (likely a common beginner mistake).

fn example(x: i32, y: i32) bool {
    return
        x < y
        || x > y + 10
        || y - x == 5;
}

The compiler gives an error about chaining comparison operators, likely because || has a higher precedence than comparison operators.

main.zig:12:24: error: comparison operators cannot be chained
            || pos.col < 0
                       ^

Expected Output

Instead, it would be much more helpful to give an error suggesting the or keyword instead of the || operator. This could be detected by using the fact that || is not defined for anything except for the Error Set Type, meaning that even without the comparison operators, it would not be allowed to compile.

@MaddyGuthridge MaddyGuthridge added the error message This issue points out an error message that is unhelpful and should be improved. label Dec 10, 2024
@Vexu Vexu added this to the 0.15.0 milestone Dec 10, 2024
@nektro
Copy link
Contributor

nektro commented Dec 10, 2024

related: #15526

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