fmt
parent
3fa9351c3e
commit
41554aafa7
|
|
@ -376,16 +376,16 @@ pub fn (typ Type) is_unsigned() bool {
|
|||
|
||||
pub fn (typ Type) flip_signedness() Type {
|
||||
r := match typ {
|
||||
i8_type {byte_type}
|
||||
i16_type {u16_type}
|
||||
int_type {u32_type}
|
||||
isize_type {usize_type}
|
||||
i64_type {u64_type}
|
||||
byte_type {i8_type}
|
||||
u16_type {i16_type}
|
||||
u32_type {int_type}
|
||||
usize_type {isize_type}
|
||||
u64_type {i64_type}
|
||||
ast.i8_type { ast.byte_type }
|
||||
ast.i16_type { ast.u16_type }
|
||||
ast.int_type { ast.u32_type }
|
||||
ast.isize_type { ast.usize_type }
|
||||
ast.i64_type { ast.u64_type }
|
||||
ast.byte_type { ast.i8_type }
|
||||
ast.u16_type { ast.i16_type }
|
||||
ast.u32_type { ast.int_type }
|
||||
ast.usize_type { ast.isize_type }
|
||||
ast.u64_type { ast.i64_type }
|
||||
else { typ }
|
||||
}
|
||||
return r
|
||||
|
|
|
|||
|
|
@ -636,8 +636,8 @@ pub fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
|
|||
rt := c.table.sym(right_type).name
|
||||
c.error('negative value cannot be compared with `$rt`', node.left.pos)
|
||||
}
|
||||
} else if is_left_type_signed != is_right_type_signed &&
|
||||
left_type.flip_signedness() != right_type {
|
||||
} else if is_left_type_signed != is_right_type_signed
|
||||
&& left_type.flip_signedness() != right_type {
|
||||
// prevent e.g. `u16(-1) == int(-1)` which is false in C
|
||||
if (is_right_type_signed && left_type in ast.int_promoted_type_idxs)
|
||||
|| (is_left_type_signed && right_type in ast.int_promoted_type_idxs) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue