authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-08 22:09:41-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-08 22:09:41-07:00
log59418d1bf6f82866a1c8f3b35fd815bb7add5129
treeab4876e312c85234a158099b075b45fee1da0879
parent470c8ca48c32d34da06e4741b8f81b6eb0d72fd7

Sema: fix Value.intFitsInType for comptime int


2 files changed, 21 insertions(+), 15 deletions(-)

src/value.zig+21-13
...@@ -1331,12 +1331,16 @@ pub const Value = extern union {...@@ -1331,12 +1331,16 @@ pub const Value = extern union {
13311331
1332 .one,1332 .one,
1333 .bool_true,1333 .bool_true,
1334 => {1334 => switch (ty.zigTypeTag()) {
1335 const info = ty.intInfo(target);1335 .Int => {
1336 return switch (info.signedness) {1336 const info = ty.intInfo(target);
1337 .signed => info.bits >= 2,1337 return switch (info.signedness) {
1338 .unsigned => info.bits >= 1,1338 .signed => info.bits >= 2,
1339 };1339 .unsigned => info.bits >= 1,
1340 };
1341 },
1342 .ComptimeInt => return true,
1343 else => unreachable,
1340 },1344 },
13411345
1342 .int_u64 => switch (ty.zigTypeTag()) {1346 .int_u64 => switch (ty.zigTypeTag()) {
...@@ -1390,13 +1394,17 @@ pub const Value = extern union {...@@ -1390,13 +1394,17 @@ pub const Value = extern union {
1390 .decl_ref,1394 .decl_ref,
1391 .function,1395 .function,
1392 .variable,1396 .variable,
1393 => {1397 => switch (ty.zigTypeTag()) {
1394 const info = ty.intInfo(target);1398 .Int => {
1395 const ptr_bits = target.cpu.arch.ptrBitWidth();1399 const info = ty.intInfo(target);
1396 return switch (info.signedness) {1400 const ptr_bits = target.cpu.arch.ptrBitWidth();
1397 .signed => info.bits > ptr_bits,1401 return switch (info.signedness) {
1398 .unsigned => info.bits >= ptr_bits,1402 .signed => info.bits > ptr_bits,
1399 };1403 .unsigned => info.bits >= ptr_bits,
1404 };
1405 },
1406 .ComptimeInt => return true,
1407 else => unreachable,
1400 },1408 },
14011409
1402 else => unreachable,1410 else => unreachable,
test/behavior/slice.zig-2
...@@ -245,8 +245,6 @@ test "C pointer slice access" {...@@ -245,8 +245,6 @@ test "C pointer slice access" {
245}245}
246246
247test "comptime slices are disambiguated" {247test "comptime slices are disambiguated" {
248 if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
249
250 try expect(sliceSum(&[_]u8{ 1, 2 }) == 3);248 try expect(sliceSum(&[_]u8{ 1, 2 }) == 3);
251 try expect(sliceSum(&[_]u8{ 3, 4 }) == 7);249 try expect(sliceSum(&[_]u8{ 3, 4 }) == 7);
252}250}