mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix inferring method receiver types (#10166)
This commit is contained in:
parent
104d9a7c8a
commit
565dbc4051
@ -503,7 +503,8 @@ pub fn (mut c Checker) infer_fn_generic_types(f ast.Fn, mut call_expr ast.CallEx
|
||||
if sym.kind == .struct_ {
|
||||
info := sym.info as ast.Struct
|
||||
receiver_generic_names := info.generic_types.map(c.table.get_type_symbol(it).name)
|
||||
if gt_name in receiver_generic_names {
|
||||
if gt_name in receiver_generic_names
|
||||
&& info.generic_types.len == info.concrete_types.len {
|
||||
idx := receiver_generic_names.index(gt_name)
|
||||
typ = info.concrete_types[idx]
|
||||
}
|
||||
|
@ -40,14 +40,30 @@ fn holder_call_21<T>(func T, a int) int {
|
||||
return h.call(a)
|
||||
}
|
||||
|
||||
fn holder_call_12<T>(func T, a int) int {
|
||||
return FnHolder1{func}.call(a)
|
||||
}
|
||||
|
||||
fn holder_call_22<T>(func T, a int) int {
|
||||
return FnHolder2{func}.call(a)
|
||||
}
|
||||
|
||||
fn test_generic_struct_with_anon_fn_parameter() {
|
||||
mut ret := holder_call_1(neg, 1)
|
||||
assert ret == -1
|
||||
ret = holder_call_11(neg, 2)
|
||||
assert ret == -2
|
||||
ret = holder_call_12(neg, 3)
|
||||
assert ret == -3
|
||||
ret = FnHolder1<fn (int) int>{neg}.call(4)
|
||||
assert ret == -4
|
||||
|
||||
ret = holder_call_2(neg, 3)
|
||||
assert ret == -3
|
||||
ret = holder_call_21(neg, 4)
|
||||
assert ret == -4
|
||||
ret = holder_call_22(neg, 5)
|
||||
assert ret == -5
|
||||
ret = FnHolder2<fn (int) int>{neg}.call(6)
|
||||
assert ret == -6
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user