Skip to content

Commit b00145a

Browse files
authored
v.generic: improve new generic stage, unwrap generic ident info, set ct_expr to false if solved, update receiver_type generic flag (#26366)
1 parent 086ecc1 commit b00145a

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

vlib/v/generics/generics.v

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,10 @@ pub fn (mut g Generics) expr(mut node ast.Expr) ast.Expr {
500500
}
501501
}
502502
for i, mut arg in args {
503-
arg.typ = g.unwrap_generic(arg.typ)
503+
if arg.typ.has_flag(.generic) {
504+
arg.typ = g.unwrap_generic(arg.typ)
505+
arg.ct_expr = false
506+
}
504507
arg.expr = g.expr(mut arg.expr)
505508
if mut arg.expr is ast.Ident {
506509
// Solve concrete_types when the type of one argument was elem in `for elem in my_array` when my_array is T
@@ -538,6 +541,9 @@ pub fn (mut g Generics) expr(mut node ast.Expr) ast.Expr {
538541
arg.expr = g.expr(mut arg.expr)
539542
}
540543
node.or_block = g.expr(mut node.or_block) as ast.OrExpr
544+
if node.receiver_type.has_flag(.generic) {
545+
node.receiver_type = node.receiver_type.clear_flag(.generic)
546+
}
541547
if node.concrete_types.len > 0 {
542548
if func := g.table.find_fn(node.name) {
543549
node.expected_arg_types = node.expected_arg_types.map(g.table.convert_generic_type(it,
@@ -657,6 +663,20 @@ pub fn (mut g Generics) expr(mut node ast.Expr) ast.Expr {
657663
} else {
658664
g.unwrap_generic(node.obj.typ)
659665
}
666+
info := match node.info {
667+
ast.IdentVar {
668+
ast.IdentInfo(ast.IdentVar{
669+
...node.info as ast.IdentVar
670+
typ: g.unwrap_generic(node.info.typ)
671+
})
672+
}
673+
ast.IdentFn {
674+
ast.IdentInfo(ast.IdentFn{
675+
...node.info as ast.IdentFn
676+
typ: g.unwrap_generic(node.info.typ)
677+
})
678+
}
679+
}
660680
return ast.Expr(ast.Ident{
661681
...node
662682
obj: ast.Var{
@@ -675,6 +695,7 @@ pub fn (mut g Generics) expr(mut node ast.Expr) ast.Expr {
675695
node.obj.ct_type_var
676696
}
677697
}
698+
info: info
678699
ct_expr: !is_ct_type_forin_val && node.ct_expr
679700
})
680701
}

0 commit comments

Comments
 (0)