checker: fix panic in generic methods (#7944)
parent
2820139216
commit
1ce93536d0
|
@ -426,6 +426,9 @@ pub fn (mut c Checker) infer_fn_types(f table.Fn, mut call_expr ast.CallExpr) {
|
|||
gt_name := 'T'
|
||||
mut typ := table.void_type
|
||||
for i, param in f.params {
|
||||
if call_expr.args.len == 0 {
|
||||
break
|
||||
}
|
||||
arg := if i != 0 && call_expr.is_method { call_expr.args[i - 1] } else { call_expr.args[i] }
|
||||
if param.typ.has_flag(.generic) {
|
||||
typ = arg.typ
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
vlib/v/checker/tests/method_generic_infer_err.vv:9:7: error: could not infer generic type `T` in call to `func`
|
||||
7 | fn main() {
|
||||
8 | data := Data{}
|
||||
9 | data.func()
|
||||
| ~~~~~~
|
||||
10 | }
|
|
@ -0,0 +1,10 @@
|
|||
struct Data {}
|
||||
|
||||
fn (_ Data) func<T>() T {
|
||||
return T{}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
data := Data{}
|
||||
data.func()
|
||||
}
|
Loading…
Reference in New Issue