stage2: misc fixes in Sema

This commit is contained in:
Veikka Tuominen
2022-02-22 15:04:12 +02:00
parent 923b07bac7
commit 92beb2b490
5 changed files with 35 additions and 21 deletions

View File

@@ -947,7 +947,7 @@ fn testRem() !void {
/// Result is an unsigned integer.
pub fn absCast(x: anytype) switch (@typeInfo(@TypeOf(x))) {
.ComptimeInt => comptime_int,
.Int => |intInfo| std.meta.Int(.unsigned, intInfo.bits),
.Int => |int_info| std.meta.Int(.unsigned, int_info.bits),
else => @compileError("absCast only accepts integers"),
} {
switch (@typeInfo(@TypeOf(x))) {
@@ -958,8 +958,9 @@ pub fn absCast(x: anytype) switch (@typeInfo(@TypeOf(x))) {
return x;
}
},
.Int => |intInfo| {
const Uint = std.meta.Int(.unsigned, intInfo.bits);
.Int => |int_info| {
if (int_info.signedness == .unsigned) return x;
const Uint = std.meta.Int(.unsigned, int_info.bits);
if (x < 0) {
return ~@bitCast(Uint, x +% -1);
} else {