Skip to content

stage2: inline fn incorrectly comptime evaluates #13164

@mitchellh

Description

@mitchellh

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.regressionIt worked in a previous version of Zig, but stopped working.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions