cgen: fix error when using anon generics fn that have generics struct arg (#10751)

pull/10770/head
zakuro 2021-07-12 01:30:41 +09:00 committed by GitHub
parent a3ed9c1bbd
commit ba9b53cc4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 2 deletions

View File

@ -192,7 +192,7 @@ pub fn (t &Table) fn_type_signature(f &Fn) string {
typ := arg.typ.set_nr_muls(0)
arg_type_sym := t.get_type_symbol(typ)
sig += arg_type_sym.str().to_lower().replace_each(['.', '__', '&', '', '[]', 'arr_', 'chan ',
'chan_', 'map[', 'map_of_', ']', '_to_'])
'chan_', 'map[', 'map_of_', ']', '_to_', '<', '_T_', ',', '_', '>', ''])
if i < f.params.len - 1 {
sig += '_'
}

View File

@ -7466,7 +7466,7 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
node.pos)
}
}
if node.language == .v && !c.is_builtin_mod {
if node.language == .v && !c.is_builtin_mod && !node.is_anon {
c.check_valid_snake_case(node.name, 'function name', node.pos)
}
if node.name == 'main.main' {

View File

@ -32,6 +32,11 @@ fn call<T>(f fn (T) T, v T) T {
return f(v)
}
struct Pair<T, U> {
a T
b U
}
fn test_generics_with_anon_generics_fn() {
mut s := MyStruct<int>{
arr: [1, 2, 3, 4, 5]
@ -44,4 +49,9 @@ fn test_generics_with_anon_generics_fn() {
assert call<string>(consume_str, '1') == '1'
assert call(consume, 1) == 1
assert call(consume_str, '1') == '1'
pair := Pair<int,string>{1, 's'}
assert call(fn (v Pair<int, string>) Pair<int, string> {
return v
}, pair) == pair
}