authorgravatar for 58830309+g-w1@users.noreply.github.comg-w1 <58830309+g-w1@users.noreply.github.com> 2020-12-22 17:05:42-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-12-23 00:05:42+02:00
logea18f894f524fdc82dc09ea9c6abf8feb93b04e8
treef909625161a772e6fff87fd776f5ede1a1a97325
parent03113d92467a99658c2606a21821b28b19dfdded
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Peer type resolution with unsigned ints and larger signed ints


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

src/stage1/ir.cpp+6-4
......@@ -12706,11 +12706,13 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1270612706 }
1270712707
1270812708 if (prev_type->id == ZigTypeIdInt &&
12709 cur_type->id == ZigTypeIdInt &&
12710 prev_type->data.integral.is_signed == cur_type->data.integral.is_signed)
12709 cur_type->id == ZigTypeIdInt)
1271112710 {
12712 if (cur_type->data.integral.bit_count > prev_type->data.integral.bit_count) {
12713 prev_inst = cur_inst;
12711 if ((prev_type->data.integral.is_signed == cur_type->data.integral.is_signed) ||
12712 (cur_type->data.integral.is_signed && !prev_type->data.integral.is_signed)) {
12713 if (cur_type->data.integral.bit_count > prev_type->data.integral.bit_count) {
12714 prev_inst = cur_inst;
12715 }
1271412716 }
1271512717 continue;
1271612718 }
test/stage1/behavior/cast.zig+9
......@@ -869,6 +869,15 @@ test "peer type resolve string lit with sentinel-terminated mutable slice" {
869869 comptime expect(@TypeOf("hi", slice) == [:0]const u8);
870870}
871871
872test "peer type unsigned int to signed" {
873 var w: u31 = 5;
874 var x: u8 = 7;
875 var y: i32 = -5;
876 var a = w + y + x;
877 comptime expect(@TypeOf(a) == i32);
878 expect(a == 7);
879}
880
872881test "peer type resolve array pointers, one of them const" {
873882 var array1: [4]u8 = undefined;
874883 const array2: [5]u8 = undefined;