checker: add type check for bit op
							parent
							
								
									dbb81b89fd
								
							
						
					
					
						commit
						5edd9cdc3a
					
				| 
						 | 
				
			
			@ -310,6 +310,14 @@ pub fn (c mut Checker) infix_expr(infix_expr mut ast.InfixExpr) table.Type {
 | 
			
		|||
		c.error('infix expr: cannot use `$right.name` (right expression) as `$left.name`',
 | 
			
		||||
			infix_expr.pos)
 | 
			
		||||
	}
 | 
			
		||||
	if infix_expr.op in [.amp, .pipe, .xor] {
 | 
			
		||||
		if !left.is_int() {
 | 
			
		||||
			c.error('operator ${infix_expr.op.str()} not defined on left type `$left.name`', infix_expr.pos)
 | 
			
		||||
		}
 | 
			
		||||
		else if !right.is_int() {
 | 
			
		||||
			c.error('operator ${infix_expr.op.str()} not defined on right type `$right.name`', infix_expr.pos)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if left_type == table.bool_type && !(infix_expr.op in [.eq, .ne, .logical_or, .and]) {
 | 
			
		||||
		c.error('bool types only have the following operators defined: `==`, `!=`, `||`, and `&&`',
 | 
			
		||||
			infix_expr.pos)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,5 @@
 | 
			
		|||
vlib/v/checker/tests/inout/bit_op_wrong_left_type_err.v:2:6: error: operator & not defined on left type `f64`
 | 
			
		||||
    1| fn main() {
 | 
			
		||||
    2|     0.5 & 1
 | 
			
		||||
               ^
 | 
			
		||||
    3| }
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,3 @@
 | 
			
		|||
fn main() {
 | 
			
		||||
	0.5 & 1
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,5 @@
 | 
			
		|||
vlib/v/checker/tests/inout/bit_op_wrong_right_type_err.v:2:4: error: operator | not defined on right type `f64`
 | 
			
		||||
    1| fn main() {
 | 
			
		||||
    2|     1 | 0.5
 | 
			
		||||
             ^
 | 
			
		||||
    3| }
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,3 @@
 | 
			
		|||
fn main() {
 | 
			
		||||
	1 | 0.5
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue