File tree Expand file tree Collapse file tree 8 files changed +22
-22
lines changed Expand file tree Collapse file tree 8 files changed +22
-22
lines changed Original file line number Diff line number Diff line change @@ -228,10 +228,10 @@ pub mut:
228
228
229
229
pub struct StructDecl {
230
230
pub :
231
- pos token.Position
232
- name string
233
- gen_types []Type
234
- is_pub bool
231
+ pos token.Position
232
+ name string
233
+ generic_types []Type
234
+ is_pub bool
235
235
// _pos fields for vfmt
236
236
mut_pos int // mut:
237
237
pub_pos int // pub:
Original file line number Diff line number Diff line change @@ -1066,17 +1066,17 @@ pub fn (mut t Table) generic_struct_insts_to_concrete() {
1066
1066
}
1067
1067
mut parent_info := parent.info as Struct
1068
1068
mut fields := parent_info.fields.clone ()
1069
- if parent_info.generic_types.len == info.generic_types .len {
1069
+ if parent_info.generic_types.len == info.concrete_types .len {
1070
1070
generic_names := parent_info.generic_types.map (t.get_type_symbol (it ).name)
1071
1071
for i in 0 .. fields.len {
1072
1072
if t_typ := t.resolve_generic_to_concrete (fields[i].typ, generic_names,
1073
- info.generic_types )
1073
+ info.concrete_types )
1074
1074
{
1075
1075
fields[i].typ = t_typ
1076
1076
}
1077
1077
}
1078
1078
parent_info.generic_types = []
1079
- parent_info.concrete_types = info.generic_types .clone ()
1079
+ parent_info.concrete_types = info.concrete_types .clone ()
1080
1080
parent_info.fields = fields
1081
1081
parent_info.parent_type = new_type (info.parent_idx).set_flag (.generic)
1082
1082
typ.is_public = true
Original file line number Diff line number Diff line change @@ -730,8 +730,8 @@ pub mut:
730
730
// instantiation of a generic struct
731
731
pub struct GenericStructInst {
732
732
pub mut :
733
- parent_idx int // idx of the base generic struct
734
- generic_types []Type
733
+ parent_idx int // idx of the base generic struct
734
+ concrete_types []Type // concrete types, e.g. <int, string>
735
735
}
736
736
737
737
pub struct Interface {
Original file line number Diff line number Diff line change @@ -6429,11 +6429,11 @@ fn (mut c Checker) post_process_generic_fns() {
6429
6429
}
6430
6430
mut node := c.file.generic_fns[i]
6431
6431
c.mod = node.mod
6432
- for gen_types in c.table.fn_generic_types[node.name] {
6433
- node.cur_generic_types = gen_types
6432
+ for generic_types in c.table.fn_generic_types[node.name] {
6433
+ node.cur_generic_types = generic_types
6434
6434
c.fn_decl (mut node)
6435
6435
if node.name in ['vweb.run_app' , 'vweb.run' ] {
6436
- c.vweb_gen_types << gen_types
6436
+ c.vweb_gen_types << generic_types
6437
6437
}
6438
6438
}
6439
6439
node.cur_generic_types = []
Original file line number Diff line number Diff line change @@ -102,9 +102,9 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl) {
102
102
f.write_language_prefix (node.language)
103
103
name := node.name.after ('.' )
104
104
f.write (name)
105
- if node.gen_types .len > 0 {
105
+ if node.generic_types .len > 0 {
106
106
f.write ('<' )
107
- gtypes := node.gen_types .map (f.table.type_to_str (it )).join (', ' )
107
+ gtypes := node.generic_types .map (f.table.type_to_str (it )).join (', ' )
108
108
f.write (gtypes)
109
109
f.write ('>' )
110
110
}
Original file line number Diff line number Diff line change @@ -129,13 +129,13 @@ fn (mut g Gen) gen_fn_decl(node ast.FnDecl, skip bool) {
129
129
// }
130
130
if node.generic_names.len > 0 && g.cur_generic_types.len == 0 { // need the cur_generic_type check to avoid inf. recursion
131
131
// loop thru each generic type and generate a function
132
- for gen_types in g.table.fn_generic_types[node.name] {
132
+ for generic_types in g.table.fn_generic_types[node.name] {
133
133
if g.pref.is_verbose {
134
- syms := gen_types .map (g.table.get_type_symbol (it ))
134
+ syms := generic_types .map (g.table.get_type_symbol (it ))
135
135
the_type := syms.map (node.name).join (', ' )
136
136
println ('gen fn `$node.name ` for type `$the_type `' )
137
137
}
138
- g.cur_generic_types = gen_types
138
+ g.cur_generic_types = generic_types
139
139
g.gen_fn_decl (node, skip)
140
140
}
141
141
g.cur_generic_types = []
Original file line number Diff line number Diff line change @@ -481,7 +481,7 @@ pub fn (mut p Parser) parse_generic_struct_inst_type(name string) ast.Type {
481
481
p.in_generic_params = true
482
482
bs_name + = '<'
483
483
bs_cname + = '_T_'
484
- mut generic_types := []ast.Type{}
484
+ mut concrete_types := []ast.Type{}
485
485
mut is_instance := false
486
486
for p.tok.kind != .eof {
487
487
gt := p.parse_type ()
@@ -491,7 +491,7 @@ pub fn (mut p Parser) parse_generic_struct_inst_type(name string) ast.Type {
491
491
gts := p.table.get_type_symbol (gt)
492
492
bs_name + = gts.name
493
493
bs_cname + = gts.cname
494
- generic_types << gt
494
+ concrete_types << gt
495
495
if p.tok.kind != .comma {
496
496
break
497
497
}
@@ -502,7 +502,7 @@ pub fn (mut p Parser) parse_generic_struct_inst_type(name string) ast.Type {
502
502
p.check (.gt)
503
503
p.in_generic_params = false
504
504
bs_name + = '>'
505
- if is_instance && generic_types .len > 0 {
505
+ if is_instance && concrete_types .len > 0 {
506
506
mut gt_idx := p.table.find_type_idx (bs_name)
507
507
if gt_idx > 0 {
508
508
return ast.new_type (gt_idx)
@@ -519,7 +519,7 @@ pub fn (mut p Parser) parse_generic_struct_inst_type(name string) ast.Type {
519
519
mod: p.mod
520
520
info: ast.GenericStructInst{
521
521
parent_idx: parent_idx
522
- generic_types: generic_types
522
+ concrete_types: concrete_types
523
523
}
524
524
})
525
525
return ast.new_type (idx)
Original file line number Diff line number Diff line change @@ -332,7 +332,7 @@ fn (mut p Parser) struct_decl() ast.StructDecl {
332
332
is_union: is_union
333
333
attrs: attrs
334
334
end_comments: end_comments
335
- gen_types : generic_types
335
+ generic_types : generic_types
336
336
embeds: embeds
337
337
}
338
338
}
You can’t perform that action at this time.
0 commit comments