Skip to content

Commit

Permalink
lint: ban comparing against undefined in Zig (#10288)
Browse files Browse the repository at this point in the history
  • Loading branch information
nektro authored Apr 16, 2024
1 parent 291a39b commit 2ae48f3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
4 changes: 4 additions & 0 deletions packages/bun-internal-test/src/banned.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
"@import(\"root\").bun.": "Only import 'bun' once",
"std.mem.indexOfAny": "Use bun.strings.indexAny or bun.strings.indexAnyComptime",
"std.debug.print": "Don't let this be committed",
" == undefined": "This is by definition Undefined Behavior.",
" != undefined": "This is by definition Undefined Behavior.",
"undefined == ": "This is by definition Undefined Behavior.",
"undefined != ": "This is by definition Undefined Behavior.",
"": ""
}
10 changes: 10 additions & 0 deletions src/bun.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3101,6 +3101,16 @@ pub fn assert(value: bool) callconv(callconv_inline) void {
}
}

/// This has no effect on the real code but capturing 'a' and 'b' into parameters makes assertion failures much easier inspect in a debugger.
pub inline fn assert_eql(a: anytype, b: anytype) void {
return assert(a == b);
}

/// This has no effect on the real code but capturing 'a' and 'b' into parameters makes assertion failures much easier inspect in a debugger.
pub inline fn assert_neql(a: anytype, b: anytype) void {
return assert(a != b);
}

pub inline fn unsafeAssert(condition: bool) void {
if (!condition) {
unreachable;
Expand Down
18 changes: 1 addition & 17 deletions src/install/semver.zig
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,6 @@ pub const String = extern struct {
};
}

pub inline fn init(
buf: string,
in: string,
) String {
if (comptime Environment.isDebug) {
const out = realInit(buf, in);
if (!out.isInline()) {
assert(@as(u64, @bitCast(out.slice(buf)[0..8].*)) != undefined);
}

return out;
} else {
return realInit(buf, in);
}
}

pub const Formatter = struct {
str: *const String,
buf: string,
Expand Down Expand Up @@ -150,7 +134,7 @@ pub const String = extern struct {
}
};

fn realInit(
pub fn init(
buf: string,
in: string,
) String {
Expand Down

0 comments on commit 2ae48f3

Please sign in to comment.