checker: fix optional or_block {none} (#7095)
							parent
							
								
									c1b25dd61d
								
							
						
					
					
						commit
						30da85a4d5
					
				| 
						 | 
				
			
			@ -24,7 +24,7 @@ pub fn (mut c Checker) check_basic(got table.Type, expected table.Type) bool {
 | 
			
		|||
		return true
 | 
			
		||||
	}
 | 
			
		||||
	if got_idx == table.none_type_idx && expected.has_flag(.optional) {
 | 
			
		||||
		return true
 | 
			
		||||
		return false
 | 
			
		||||
	}
 | 
			
		||||
	// allow pointers to be initialized with 0. TODO: use none instead
 | 
			
		||||
	if exp_is_ptr && got_idx == table.int_type_idx {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,7 @@
 | 
			
		|||
vlib/v/checker/tests/optional_or_block_none_err.vv:18:3: error: wrong return type `none` in the `or {}` block, expected `Animal`
 | 
			
		||||
   16 | fn main() {
 | 
			
		||||
   17 |     mut dog := new_animal(9) or {
 | 
			
		||||
   18 |         none
 | 
			
		||||
      |         ~~~~
 | 
			
		||||
   19 |     }
 | 
			
		||||
   20 |
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,22 @@
 | 
			
		|||
module main
 | 
			
		||||
 | 
			
		||||
struct Animal {
 | 
			
		||||
	mut:
 | 
			
		||||
		height byte
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn new_animal(height byte) ?Animal {
 | 
			
		||||
	if height < 10 {
 | 
			
		||||
		return error('Too small to be an animal!')
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return Animal{ height: height }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn main() {
 | 
			
		||||
	mut dog := new_animal(9) or {
 | 
			
		||||
		none
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	println(dog)
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue