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

Misleading error when using || instead of or with comparisons #15526

Open
IntegratedQuantum opened this issue Apr 30, 2023 · 1 comment
Open
Labels
error message This issue points out an error message that is unhelpful and should be improved.
Milestone

Comments

@IntegratedQuantum
Copy link
Contributor

Zig Version

0.11.0-dev.2868+1a455b2dd

Steps to Reproduce and Observed Output

pub fn main() !void {
	var a: u16 = 0;
	if(a == 0 || true) return;
}

Output:

$ zig run test.zig
test.zig:3:10: error: expected type 'type', found 'comptime_int'
 if(a == 0 || true) return;
         ^

Expected Output

If I add some parenthesis around the a == 0 then I get a more useful error:

$ zig run test.zig
test.zig:3:5: error: expected error set type, found 'bool'
 if((a == 0) || true) return;
    ^~~~~~~~
test.zig:3:14: note: '||' merges error sets; 'or' performs boolean OR
 if((a == 0) || true) return;
    ~~~~~~~~~^~~~~~~
@IntegratedQuantum IntegratedQuantum added the error message This issue points out an error message that is unhelpful and should be improved. label Apr 30, 2023
@Vexu Vexu added this to the 0.13.0 milestone Apr 30, 2023
@paulstelian97
Copy link

Error seems to be even more misleading because of different operator priorities between the two. Would the compatibility break if this changes?

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