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

checker: check generics struct init that types mismatch (fix #12115) (#12120)

This commit is contained in:
yuyi 2021-10-09 20:03:37 +08:00 committed by GitHub
parent 7a6491b9b0
commit 093cab6f56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 4 deletions

View File

@ -856,10 +856,13 @@ pub fn (mut c Checker) generic_insts_to_concrete() {
}
typ.is_public = true
typ.kind = parent.kind
}
parent_sym := c.table.get_type_symbol(parent_info.parent_type)
for method in parent_sym.methods {
c.table.register_fn_concrete_types(method.name, info.concrete_types)
parent_sym := c.table.get_type_symbol(parent_info.parent_type)
for method in parent_sym.methods {
c.table.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')
}
}
ast.Interface {

View File

@ -0,0 +1 @@
generic error: the number of generic types of struct `main.Example` is inconsistent with the concrete types

View File

@ -0,0 +1,11 @@
struct Example<T, V> {
key T
value V
}
fn main() {
example := Example<string>{
key: 'key'
value: 'value'
}
}