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

Wrong usage of @subWithOverflow return value results in confusing error message #14022

Closed
speps opened this issue Dec 21, 2022 · 0 comments · Fixed by #14024
Closed

Wrong usage of @subWithOverflow return value results in confusing error message #14022

speps opened this issue Dec 21, 2022 · 0 comments · Fixed by #14024
Labels
error message This issue points out an error message that is unhelpful and should be improved.

Comments

@speps
Copy link

speps commented Dec 21, 2022

Zig Version

0.11.0-dev.866+f24c77fc4

Steps to Reproduce and Observed Output

When trying to use @subWithOverflow in some code, I found a very confusing error message:

example.zig:5:47: error: expected type 'u1', found 'bool'
    const carry = @subWithOverflow(u32, 1, 2, &result);
                                              ^~~~~~~
const std = @import("std");

pub fn main() !void {
    var result: u32 = 0;
    const carry = @subWithOverflow(u32, 1, 2, &result);
    var err: u1 = @as(u1, carry);
    std.debug.print("{d}\n", err);
}

The issue is that the reported line/character is wrong when using this builtin function.

Reproduced example: https://godbolt.org/z/sz6j9E65f (0.11.0-dev.866+f24c77fc4 at the time of writing)

Expected Output

The problem happens when using the return value so it should be reported at the place where the return value from @subWithOverflow is used.

@speps speps added the error message This issue points out an error message that is unhelpful and should be improved. label Dec 21, 2022
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

Successfully merging a pull request may close this issue.

1 participant