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

stage2: inline fn incorrectly comptime evaluates #13164

Closed
mitchellh opened this issue Oct 15, 2022 · 0 comments · Fixed by #13219
Closed

stage2: inline fn incorrectly comptime evaluates #13164

mitchellh opened this issue Oct 15, 2022 · 0 comments · Fixed by #13219
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness. regression It worked in a previous version of Zig, but stopped working.
Milestone

Comments

@mitchellh
Copy link
Contributor

mitchellh commented Oct 15, 2022

Zig Version

0.10.0-dev.4333+f5f28e0d2

Steps to Reproduce

const std = @import("std");

inline fn setLimits(min: ?u32, max: ?u32) void {
    if (min != null and max != null) {
        std.debug.assert(min.? <= max.?);
    }
}

pub fn main() void {
    var x: u32 = 42;
    setLimits(x, null);
}

(Sorry its not a test because my test was broken with this build thats fixed later)

Other notes:

  • inline is required. If inline is removed, this issue does not reproduce.
  • Two args required (at least). When I removed one arg, this issue did not reproduce.
  • Runtime argument is required for one of the args. If both are comptime, this evaluates correctly.

Expected Behavior

Should compile.

Actual Behavior

$ zig run test.zig
test.zig:5:38: error: unable to unwrap null
        std.debug.assert(min.? <= max.?);
                                  ~~~^~
test.zig:11:14: note: called from here
    setLimits(x, null);
    ~~~~~~~~~^~~~~~~~~

(Note: -fstage1 works fine)

@mitchellh mitchellh added the bug Observed behavior contradicts documented or intended behavior label Oct 15, 2022
@andrewrk andrewrk added frontend Tokenization, parsing, AstGen, Sema, and Liveness. regression It worked in a previous version of Zig, but stopped working. labels Oct 15, 2022
@andrewrk andrewrk added this to the 0.10.0 milestone Oct 15, 2022
This was linked to pull requests Oct 20, 2022
This was unlinked from pull requests Oct 20, 2022
@Vexu Vexu linked a pull request Oct 20, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness. regression It worked in a previous version of Zig, but stopped working.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants