mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: check assigning generic function to a variable (#16507)
This commit is contained in:
parent
27cdf5ae0e
commit
7c7ebd648d
@ -65,6 +65,11 @@ fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
|
||||
c.error('cannot use `none` in `unsafe` blocks', right.expr.pos)
|
||||
}
|
||||
}
|
||||
if mut right is ast.AnonFn {
|
||||
if right.decl.generic_names.len > 0 {
|
||||
c.error('cannot assign generic function to a variable', right.decl.pos)
|
||||
}
|
||||
}
|
||||
}
|
||||
if node.left.len != right_len {
|
||||
if right_first is ast.CallExpr {
|
||||
|
12
vlib/v/checker/tests/assign_generic_fn_err.out
Normal file
12
vlib/v/checker/tests/assign_generic_fn_err.out
Normal file
@ -0,0 +1,12 @@
|
||||
vlib/v/checker/tests/assign_generic_fn_err.vv:2:9: error: cannot assign generic function to a variable
|
||||
1 | fn main() {
|
||||
2 | fun := fn <T> (value T) T {
|
||||
| ~~~~~~~~~~~~~~~~~~~~
|
||||
3 | return value
|
||||
4 | }
|
||||
vlib/v/checker/tests/assign_generic_fn_err.vv:6:13: error: a non generic function called like a generic one
|
||||
4 | }
|
||||
5 |
|
||||
6 | println(fun<int>(100))
|
||||
| ~~~~~
|
||||
7 | }
|
7
vlib/v/checker/tests/assign_generic_fn_err.vv
Normal file
7
vlib/v/checker/tests/assign_generic_fn_err.vv
Normal file
@ -0,0 +1,7 @@
|
||||
fn main() {
|
||||
fun := fn <T> (value T) T {
|
||||
return value
|
||||
}
|
||||
|
||||
println(fun<int>(100))
|
||||
}
|
Loading…
Reference in New Issue
Block a user