table: fix generic method with multi generic types (#12297)
parent
508f29c101
commit
f62b2dcfa7
|
@ -1690,7 +1690,9 @@ 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 {
|
||||
t.register_fn_concrete_types(method.name, info.concrete_types)
|
||||
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')
|
||||
|
|
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue