mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 04:48:20 +00:00
Sema: fix Value.intFitsInType for comptime int
This commit is contained in:
parent
470c8ca48c
commit
59418d1bf6
@ -1331,12 +1331,16 @@ pub const Value = extern union {
|
||||
|
||||
.one,
|
||||
.bool_true,
|
||||
=> {
|
||||
const info = ty.intInfo(target);
|
||||
return switch (info.signedness) {
|
||||
.signed => info.bits >= 2,
|
||||
.unsigned => info.bits >= 1,
|
||||
};
|
||||
=> switch (ty.zigTypeTag()) {
|
||||
.Int => {
|
||||
const info = ty.intInfo(target);
|
||||
return switch (info.signedness) {
|
||||
.signed => info.bits >= 2,
|
||||
.unsigned => info.bits >= 1,
|
||||
};
|
||||
},
|
||||
.ComptimeInt => return true,
|
||||
else => unreachable,
|
||||
},
|
||||
|
||||
.int_u64 => switch (ty.zigTypeTag()) {
|
||||
@ -1390,13 +1394,17 @@ pub const Value = extern union {
|
||||
.decl_ref,
|
||||
.function,
|
||||
.variable,
|
||||
=> {
|
||||
const info = ty.intInfo(target);
|
||||
const ptr_bits = target.cpu.arch.ptrBitWidth();
|
||||
return switch (info.signedness) {
|
||||
.signed => info.bits > ptr_bits,
|
||||
.unsigned => info.bits >= ptr_bits,
|
||||
};
|
||||
=> switch (ty.zigTypeTag()) {
|
||||
.Int => {
|
||||
const info = ty.intInfo(target);
|
||||
const ptr_bits = target.cpu.arch.ptrBitWidth();
|
||||
return switch (info.signedness) {
|
||||
.signed => info.bits > ptr_bits,
|
||||
.unsigned => info.bits >= ptr_bits,
|
||||
};
|
||||
},
|
||||
.ComptimeInt => return true,
|
||||
else => unreachable,
|
||||
},
|
||||
|
||||
else => unreachable,
|
||||
|
||||
@ -245,8 +245,6 @@ test "C pointer slice access" {
|
||||
}
|
||||
|
||||
test "comptime slices are disambiguated" {
|
||||
if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
|
||||
|
||||
try expect(sliceSum(&[_]u8{ 1, 2 }) == 3);
|
||||
try expect(sliceSum(&[_]u8{ 3, 4 }) == 7);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user