don't error for types with the same size
parent
d91a24a372
commit
3fa9351c3e
|
|
@ -374,6 +374,23 @@ pub fn (typ Type) is_unsigned() bool {
|
||||||
return typ.idx() in ast.unsigned_integer_type_idxs
|
return typ.idx() in ast.unsigned_integer_type_idxs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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}
|
||||||
|
else {typ}
|
||||||
|
}
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
pub fn (typ Type) is_int_literal() bool {
|
pub fn (typ Type) is_int_literal() bool {
|
||||||
return int(typ) == ast.int_literal_type_idx
|
return int(typ) == ast.int_literal_type_idx
|
||||||
|
|
|
||||||
|
|
@ -79,3 +79,9 @@ fn test_derive() {
|
||||||
assert t2.has_flag(ast.TypeFlag.generic) == true
|
assert t2.has_flag(ast.TypeFlag.generic) == true
|
||||||
assert t2.nr_muls() == 10
|
assert t2.nr_muls() == 10
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_flip_signedness() {
|
||||||
|
assert ast.i8_type.flip_signedness() == ast.byte_type
|
||||||
|
assert ast.u16_type.flip_signedness() == ast.i16_type
|
||||||
|
assert ast.isize_type.flip_signedness() == ast.usize_type
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -636,7 +636,8 @@ pub fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
|
||||||
rt := c.table.sym(right_type).name
|
rt := c.table.sym(right_type).name
|
||||||
c.error('negative value cannot be compared with `$rt`', node.left.pos)
|
c.error('negative value cannot be compared with `$rt`', node.left.pos)
|
||||||
}
|
}
|
||||||
} else if is_left_type_signed != is_right_type_signed {
|
} 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
|
// 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)
|
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) {
|
|| (is_left_type_signed && right_type in ast.int_promoted_type_idxs) {
|
||||||
|
|
|
||||||
|
|
@ -778,7 +778,7 @@ pub fn (mut bmp BitMap) draw_glyph(index u16) (int, int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if count == glyph.contour_ends[c] {
|
if count == int(glyph.contour_ends[c]) {
|
||||||
// dprintln("count == glyph.contour_ends[count]")
|
// dprintln("count == glyph.contour_ends[count]")
|
||||||
if s == 2 { // final point was off-curve. connect to start
|
if s == 2 { // final point was off-curve. connect to start
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue