1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: fix type error in f<T>(fn (v T)) with multiple different Ts (#10154)

This commit is contained in:
zakuro 2021-05-21 12:13:04 +09:00 committed by GitHub
parent f7cd95472a
commit be92f81b2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -1211,6 +1211,7 @@ pub fn (mut t Table) resolve_generic_to_concrete(generic_type Type, generic_name
func.return_type = typ func.return_type = typ
} }
} }
func.params = func.params.clone()
for mut param in func.params { for mut param in func.params {
if param.typ.has_flag(.generic) { if param.typ.has_flag(.generic) {
if typ := t.resolve_generic_to_concrete(param.typ, generic_names, concrete_types, if typ := t.resolve_generic_to_concrete(param.typ, generic_names, concrete_types,

View File

@ -24,6 +24,14 @@ pub fn consume(data int) int {
return data return data
} }
pub fn consume_str(data string) string {
return data
}
fn call<T>(f fn (T) T, v T) T {
return f(v)
}
fn test_generics_with_anon_generics_fn() { fn test_generics_with_anon_generics_fn() {
mut s := MyStruct<int>{ mut s := MyStruct<int>{
arr: [1, 2, 3, 4, 5] arr: [1, 2, 3, 4, 5]
@ -31,4 +39,9 @@ fn test_generics_with_anon_generics_fn() {
y := s.iterate<int>(consume) y := s.iterate<int>(consume)
println(y) println(y)
assert y == 15 assert y == 15
assert call<int>(consume, 1) == 1
assert call<string>(consume_str, '1') == '1'
assert call(consume, 1) == 1
assert call(consume_str, '1') == '1'
} }