From 59418d1bf6f82866a1c8f3b35fd815bb7add5129 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 8 Feb 2022 22:09:41 -0700 Subject: [PATCH] Sema: fix Value.intFitsInType for comptime int --- src/value.zig | 34 +++++++++++++++++++++------------- test/behavior/slice.zig | 2 -- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/value.zig b/src/value.zig index acc3fa3d74b41974b749425c2fc9d1b70e3356de..9e1f4c0ed6842900410611348a125c65b8df66af 100644 --- a/src/value.zig +++ b/src/value.zig @@ -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, diff --git a/test/behavior/slice.zig b/test/behavior/slice.zig index 4ec5f1181765e00ce7310c8b51dfd72b7f514f0d..902ba49a6fa47e99d8efb5d1ac240953090142f5 100644 --- a/test/behavior/slice.zig +++ b/test/behavior/slice.zig @@ -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); } -- 2.54.0