checker: add check for call expr in map/filter (#9559)
							parent
							
								
									7385f8e56b
								
							
						
					
					
						commit
						d8efe249ce
					
				| 
						 | 
					@ -0,0 +1,7 @@
 | 
				
			||||||
 | 
					fn main() {
 | 
				
			||||||
 | 
						list := [1,2,3].filter(stringsss(it))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fn stringsss(arg int) string {
 | 
				
			||||||
 | 
						return ''
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -1409,6 +1409,13 @@ fn (mut c Checker) check_map_and_filter(is_map bool, elem_typ ast.Type, call_exp
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							ast.CallExpr {
 | 
				
			||||||
 | 
								if is_map && arg_expr.return_type == table.void_type {
 | 
				
			||||||
 | 
									c.error('type mismatch, `$arg_expr.name` does not return anything', arg_expr.pos)
 | 
				
			||||||
 | 
								} else if !is_map && arg_expr.return_type != table.bool_type {
 | 
				
			||||||
 | 
									c.error('type mismatch, `$arg_expr.name` must return a bool', arg_expr.pos)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		else {}
 | 
							else {}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,6 @@
 | 
				
			||||||
 | 
					vlib/v/checker/tests/filter_func_return_nonbool_err.vv:2:25: error: type mismatch, `stringsss` must return a bool
 | 
				
			||||||
 | 
					    1 | fn main() {
 | 
				
			||||||
 | 
					    2 |     list := [1,2,3].filter(stringsss(it))
 | 
				
			||||||
 | 
					      |                            ~~~~~~~~~~~~~
 | 
				
			||||||
 | 
					    3 | }
 | 
				
			||||||
 | 
					    4 |
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,7 @@
 | 
				
			||||||
 | 
					fn main() {
 | 
				
			||||||
 | 
						list := [1,2,3].filter(stringsss(it))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fn stringsss(arg int) string {
 | 
				
			||||||
 | 
						return ''
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,6 @@
 | 
				
			||||||
 | 
					vlib/v/checker/tests/map_func_void_return_err.vv:2:22: error: type mismatch, `voids` does not return anything
 | 
				
			||||||
 | 
					    1 | fn main() {
 | 
				
			||||||
 | 
					    2 |     list := [1,2,3].map(voids(it))
 | 
				
			||||||
 | 
					      |                         ~~~~~~~~~
 | 
				
			||||||
 | 
					    3 | }
 | 
				
			||||||
 | 
					    4 |
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,7 @@
 | 
				
			||||||
 | 
					fn main() {
 | 
				
			||||||
 | 
						list := [1,2,3].map(voids(it))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fn voids(arg int) {
 | 
				
			||||||
 | 
						println(arg)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue