checker: fix for in range type mismatch
							parent
							
								
									5edd9cdc3a
								
							
						
					
					
						commit
						be3bd520f6
					
				| 
						 | 
				
			
			@ -1105,6 +1105,16 @@ fn (c mut Checker) stmt(node ast.Stmt) {
 | 
			
		|||
			c.in_for_count++
 | 
			
		||||
			typ := c.expr(it.cond)
 | 
			
		||||
			if it.is_range {
 | 
			
		||||
				high_type := c.expr(it.high)
 | 
			
		||||
				if typ in table.integer_type_idxs && high_type !in table.integer_type_idxs {
 | 
			
		||||
					c.error('range types do not match', it.cond.position())
 | 
			
		||||
				} else if typ in table.float_type_idxs || high_type in table.float_type_idxs {
 | 
			
		||||
					c.error('range type can not be float', it.cond.position())
 | 
			
		||||
				} else if typ == table.bool_type_idx || high_type == table.bool_type_idx {
 | 
			
		||||
					c.error('range type can not be bool', it.cond.position())
 | 
			
		||||
				} else if typ == table.string_type_idx || high_type == table.string_type_idx {
 | 
			
		||||
					c.error('range type can not be string', it.cond.position())
 | 
			
		||||
				}
 | 
			
		||||
				c.expr(it.high)
 | 
			
		||||
			} else {
 | 
			
		||||
				mut scope := c.file.scope.innermost(it.pos.pos)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,6 @@
 | 
			
		|||
vlib/v/checker/tests/inout/for_in_range_not_match_type.v:2:11: error: range types do not match
 | 
			
		||||
    1| fn main() {
 | 
			
		||||
    2|     for i in 10..10.5 {
 | 
			
		||||
                    ~~
 | 
			
		||||
    3|         println(i)
 | 
			
		||||
    4|     }
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,5 @@
 | 
			
		|||
fn main() {
 | 
			
		||||
	for i in 10..10.5 {
 | 
			
		||||
		println(i)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,6 @@
 | 
			
		|||
vlib/v/checker/tests/inout/for_in_range_string_type.v:2:11: error: range type can not be string
 | 
			
		||||
    1| fn main() {
 | 
			
		||||
    2|     for i in 'a'..'b' {
 | 
			
		||||
                    ~~~
 | 
			
		||||
    3|         println(i)
 | 
			
		||||
    4|     }
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,5 @@
 | 
			
		|||
fn main() {
 | 
			
		||||
	for i in 'a'..'b' {
 | 
			
		||||
		println(i)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue