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

checker: fix generic struct field init recursively (related #19014) (#19025)

This commit is contained in:
yuyi 2023-08-01 12:20:33 +08:00 committed by GitHub
parent 5061aeee64
commit a1aca4c578
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View File

@ -318,6 +318,9 @@ fn (mut c Checker) struct_init(mut node ast.StructInit, is_field_zero_struct_ini
} }
} }
struct_sym := c.table.sym(node.typ) struct_sym := c.table.sym(node.typ)
mut old_inside_generic_struct_init := false
mut old_cur_struct_generic_types := []ast.Type{}
mut old_cur_struct_concrete_types := []ast.Type{}
if struct_sym.info is ast.Struct { if struct_sym.info is ast.Struct {
// check if the generic param types have been defined // check if the generic param types have been defined
for ct in struct_sym.info.concrete_types { for ct in struct_sym.info.concrete_types {
@ -357,13 +360,16 @@ fn (mut c Checker) struct_init(mut node ast.StructInit, is_field_zero_struct_ini
} }
if struct_sym.info.generic_types.len > 0 if struct_sym.info.generic_types.len > 0
&& struct_sym.info.generic_types.len == struct_sym.info.concrete_types.len { && struct_sym.info.generic_types.len == struct_sym.info.concrete_types.len {
old_inside_generic_struct_init = c.inside_generic_struct_init
old_cur_struct_generic_types = c.cur_struct_generic_types.clone()
old_cur_struct_concrete_types = c.cur_struct_concrete_types.clone()
c.inside_generic_struct_init = true c.inside_generic_struct_init = true
c.cur_struct_generic_types = struct_sym.info.generic_types.clone() c.cur_struct_generic_types = struct_sym.info.generic_types.clone()
c.cur_struct_concrete_types = struct_sym.info.concrete_types.clone() c.cur_struct_concrete_types = struct_sym.info.concrete_types.clone()
defer { defer {
c.inside_generic_struct_init = false c.inside_generic_struct_init = old_inside_generic_struct_init
c.cur_struct_generic_types = [] c.cur_struct_generic_types = old_cur_struct_generic_types
c.cur_struct_concrete_types = [] c.cur_struct_concrete_types = old_cur_struct_concrete_types
} }
} }
} else if struct_sym.info is ast.Alias { } else if struct_sym.info is ast.Alias {

View File

@ -7,7 +7,6 @@ struct BloomFilter1[T] {
[heap] [heap]
struct BloomFilter2[T] { struct BloomFilter2[T] {
// TODO V bug
hash_func fn (T) u32 = default_cb[T] // hash function, input [T] , output u32 hash_func fn (T) u32 = default_cb[T] // hash function, input [T] , output u32
table_size int // every entry is one-bit, packed into `table` table_size int // every entry is one-bit, packed into `table`
num_functions int // 1~16 num_functions int // 1~16