mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
all: implement multiple generics (#8231)
This commit is contained in:
@@ -324,7 +324,7 @@ pub:
|
||||
pos token.Position // function declaration position
|
||||
body_pos token.Position // function bodys position
|
||||
file string
|
||||
is_generic bool
|
||||
generic_params []GenericParam
|
||||
is_direct_arr bool // direct array access
|
||||
attrs []table.Attr
|
||||
pub mut:
|
||||
@@ -336,6 +336,11 @@ pub mut:
|
||||
scope &Scope
|
||||
}
|
||||
|
||||
pub struct GenericParam {
|
||||
pub:
|
||||
name string
|
||||
}
|
||||
|
||||
// break, continue
|
||||
pub struct BranchStmt {
|
||||
pub:
|
||||
@@ -362,7 +367,7 @@ pub mut:
|
||||
receiver_type table.Type // User
|
||||
return_type table.Type
|
||||
should_be_skipped bool
|
||||
generic_type table.Type // TODO array, to support multiple types
|
||||
generic_types []table.Type
|
||||
generic_list_pos token.Position
|
||||
free_receiver bool // true if the receiver expression needs to be freed
|
||||
scope &Scope
|
||||
|
||||
@@ -59,8 +59,16 @@ pub fn (node &FnDecl) stringify(t &table.Table, cur_mod string, m2a map[string]s
|
||||
if name in ['+', '-', '*', '/', '%', '<', '>', '==', '!=', '>=', '<='] {
|
||||
f.write(' ')
|
||||
}
|
||||
if node.is_generic {
|
||||
f.write('<T>')
|
||||
if node.generic_params.len > 0 {
|
||||
f.write('<')
|
||||
for i, param in node.generic_params {
|
||||
is_last := i == node.generic_params.len - 1
|
||||
f.write(param.name)
|
||||
if !is_last {
|
||||
f.write(', ')
|
||||
}
|
||||
}
|
||||
f.write('>')
|
||||
}
|
||||
f.write('(')
|
||||
for i, arg in node.params {
|
||||
|
||||
Reference in New Issue
Block a user