From 52ebba6bdf5662353ce11a701a3361cc0616c01c Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 4 Jan 2024 00:44:44 -0700 Subject: [PATCH] `@shlExact` fixups * Add clarification in langref * move test case to behavior tests --- doc/langref.html.in | 5 +++++ test/behavior/math.zig | 2 ++ test/cases/shl_exact_comptime_int_lhs.zig | 6 ------ 3 files changed, 7 insertions(+), 6 deletions(-) delete mode 100644 test/cases/shl_exact_comptime_int_lhs.zig diff --git a/doc/langref.html.in b/doc/langref.html.in index c07633273b..7b5d086f2d 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -9163,6 +9163,11 @@ test "@setRuntimeSafety" { The type of {#syntax#}shift_amt{#endsyntax#} is an unsigned integer with {#syntax#}log2(@typeInfo(T).Int.bits){#endsyntax#} bits. This is because {#syntax#}shift_amt >= @typeInfo(T).Int.bits{#endsyntax#} is undefined behavior.

+

+ {#syntax#}comptime_int{#endsyntax#} is modeled as an integer with an infinite number of bits, + meaning that in such case, {#syntax#}@shlExact{#endsyntax#} always produces a result and + cannot produce a compile error. +

{#see_also|@shrExact|@shlWithOverflow#} {#header_close#} diff --git a/test/behavior/math.zig b/test/behavior/math.zig index 3d3c282854..4f9f7a673d 100644 --- a/test/behavior/math.zig +++ b/test/behavior/math.zig @@ -1314,6 +1314,8 @@ test "exact shift left" { try testShlExact(0b00110101); try comptime testShlExact(0b00110101); + + if (@shlExact(1, 1) != 2) @compileError("should be 2"); } fn testShlExact(x: u8) !void { const shifted = @shlExact(x, 2); diff --git a/test/cases/shl_exact_comptime_int_lhs.zig b/test/cases/shl_exact_comptime_int_lhs.zig deleted file mode 100644 index 60860f5113..0000000000 --- a/test/cases/shl_exact_comptime_int_lhs.zig +++ /dev/null @@ -1,6 +0,0 @@ -export fn entry() void { - if (@shlExact(1, 1) != 2) @compileError("should be 2"); -} - -// compile -// output_mode=Obj