Skip to content

Bitwise complement should propagate result type #24167

@matklad

Description

@matklad

Zig Version

0.14.0

Steps to Reproduce and Observed Behavior

λ cat main.zig
const std = @import("std");
const assert = std.debug.assert;

pub fn main() void {
    const x: u64 = ~0;
    assert(x == std.math.maxInt(u64));
}
matklad@TigerMac ~/p/tb/work (matklad/fix-assert *)
λ ~/zig-0.14/zig run main.zig
main.zig:5:20: error: unable to perform binary not operation on type 'comptime_int'
    const x: u64 = ~0;

Expected Behavior

Program exists with zero.

Metadata

Metadata

Assignees

No one assigned

    Labels

    breakingImplementing this issue could cause existing code to no longer compile or have different behavior.enhancementSolving this issue will likely involve adding new logic or components to the codebase.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions