checker: add checks and test for ~ operator
parent
b4ad174b7f
commit
56ae3797dd
|
@ -1952,6 +1952,9 @@ pub fn (mut c Checker) expr(node ast.Expr) table.Type {
|
||||||
if it.op == .mul && right_type.is_ptr() {
|
if it.op == .mul && right_type.is_ptr() {
|
||||||
return right_type.deref()
|
return right_type.deref()
|
||||||
}
|
}
|
||||||
|
if it.op == .bit_not && !right_type.is_int(){
|
||||||
|
c.error('operator ~ only defined on int types', it.pos)
|
||||||
|
}
|
||||||
if it.op == .not && right_type != table.bool_type_idx {
|
if it.op == .not && right_type != table.bool_type_idx {
|
||||||
c.error('! operator can only be used with bool types', it.pos)
|
c.error('! operator can only be used with bool types', it.pos)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
vlib/v/checker/tests/invert_other_types_bits_error.v:2:13: error: operator ~ only defined on int types
|
||||||
|
1 | fn main() {
|
||||||
|
2 | println(~3.0)
|
||||||
|
| ^
|
||||||
|
3 | println(~10.5)
|
||||||
|
4 | println(~'2')
|
||||||
|
vlib/v/checker/tests/invert_other_types_bits_error.v:3:13: error: operator ~ only defined on int types
|
||||||
|
1 | fn main() {
|
||||||
|
2 | println(~3.0)
|
||||||
|
3 | println(~10.5)
|
||||||
|
| ^
|
||||||
|
4 | println(~'2')
|
||||||
|
5 | println(~[2, 4, 6])
|
||||||
|
vlib/v/checker/tests/invert_other_types_bits_error.v:4:13: error: operator ~ only defined on int types
|
||||||
|
2 | println(~3.0)
|
||||||
|
3 | println(~10.5)
|
||||||
|
4 | println(~'2')
|
||||||
|
| ^
|
||||||
|
5 | println(~[2, 4, 6])
|
||||||
|
6 | }
|
||||||
|
vlib/v/checker/tests/invert_other_types_bits_error.v:5:13: error: operator ~ only defined on int types
|
||||||
|
3 | println(~10.5)
|
||||||
|
4 | println(~'2')
|
||||||
|
5 | println(~[2, 4, 6])
|
||||||
|
| ^
|
||||||
|
6 | }
|
|
@ -0,0 +1,6 @@
|
||||||
|
fn main() {
|
||||||
|
println(~3.0)
|
||||||
|
println(~10.5)
|
||||||
|
println(~'2')
|
||||||
|
println(~[2, 4, 6])
|
||||||
|
}
|
Loading…
Reference in New Issue