checker: check generics fn called outside of generic fn (#9984)

pull/9976/head^2
yuyi 2021-05-04 00:50:08 +08:00 committed by GitHub
parent ddc003380c
commit 1d045e5496
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 0 deletions

View File

@ -2135,6 +2135,10 @@ pub fn (mut c Checker) fn_call(mut call_expr ast.CallExpr) ast.Type {
concrete_types << concrete_type
}
}
if c.cur_fn.cur_concrete_types.len == 0 && has_generic {
c.error('generic fn using generic types cannot be called outside of generic fn',
call_expr.pos)
}
if has_generic {
mut no_exists := true
if c.mod != '' && !fn_name.contains('.') {

View File

@ -0,0 +1,6 @@
vlib/v/checker/tests/generics_fn_called_outside_of_generic_fn.vv:4:2: error: generic fn using generic types cannot be called outside of generic fn
2 |
3 | fn main() {
4 | foo<T>()
| ~~~~~~~~
5 | }

View File

@ -0,0 +1,5 @@
fn foo<T>() {}
fn main() {
foo<T>()
}