table: fix generic method with multi generic types (#12297)

pull/12301/head
yuyi 2021-10-26 16:00:27 +08:00 committed by GitHub
parent 508f29c101
commit f62b2dcfa7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 1 deletions

View File

@ -1690,8 +1690,10 @@ pub fn (mut t Table) generic_insts_to_concrete() {
parent_sym := t.get_type_symbol(parent_info.parent_type)
for method in parent_sym.methods {
if method.generic_names.len == info.concrete_types.len {
t.register_fn_concrete_types(method.name, info.concrete_types)
}
}
} else {
util.verror('generic error', 'the number of generic types of struct `$parent.name` is inconsistent with the concrete types')
}

View File

@ -0,0 +1,30 @@
interface Something {
i int
}
struct Some {
i int
}
struct App<M> {
f M
}
fn (mut self App<M>) next<M, T>(input T) f64 {
$if M is Something {
return 0
} $else {
panic('${typeof(M.typ).name} is not supported')
return 1
}
return 1
}
fn test_generic_method_with_multi_types() {
mut app := App<Some>{
f: Some{
i: 10
}
}
assert app.next(1) == 0
}