Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Dec 29, 2024
1 parent 100021f commit a4c2a38
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion vlib/v/checker/assign.v
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
&& right.args[0].expr is ast.AsCast {
left.obj.ct_type_var = .generic_var
fn_ret_type := c.table.find_or_register_array(c.unwrap_generic((right.args[0].expr as ast.AsCast).typ))
c.comptime.type_map['g.${left.name}.${left.obj.pos.pos}'] = fn_ret_type
c.type_resolver.type_map['g.${left.name}.${left.obj.pos.pos}'] = fn_ret_type
} else if left.obj.ct_type_var in [.generic_var, .no_comptime]
&& c.table.cur_fn != unsafe { nil }
&& c.table.cur_fn.generic_names.len != 0
Expand Down
1 change: 0 additions & 1 deletion vlib/v/checker/infix.v
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,6 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
}
// []T << T or []T << []T
unwrapped_right_type := c.unwrap_generic(right_type)
println('>> ${c.table.type_to_str(left_value_type)} | ${c.table.type_to_str(unwrapped_right_type)}')
if c.check_types(unwrapped_right_type, left_value_type) {
// []&T << T is wrong: we check for that, !(T.is_ptr()) && ?(&T).is_ptr()
if !(!unwrapped_right_type.is_ptr() && left_value_type.is_ptr()
Expand Down
18 changes: 16 additions & 2 deletions vlib/v/gen/c/array.v
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,15 @@ fn (mut g Gen) gen_array_map(node ast.CallExpr) {
g.past_tmp_var_done(past)
}

ret_styp := g.styp(node.return_type)
ret_sym := g.table.final_sym(node.return_type)
return_type := if g.type_resolver.is_generic_expr(node.args[0].expr) {
g.table.find_or_register_array(g.type_resolver.unwrap_generic_expr(node.args[0].expr,
node.return_type))
} else {
node.return_type
}
ret_styp := g.styp(return_type)
ret_sym := g.table.final_sym(return_type)

left_is_array := g.table.final_sym(node.left_type).kind == .array
inp_sym := g.table.final_sym(node.receiver_type)

Expand Down Expand Up @@ -608,6 +615,13 @@ fn (mut g Gen) gen_array_map(node ast.CallExpr) {
g.expr(expr)
}
}
ast.AsCast {
if expr.typ.has_flag(.generic) {
ret_elem_styp = g.styp(g.unwrap_generic(expr.typ))
}
g.write('${ret_elem_styp} ${tmp_map_expr_result_name} = ')
g.expr(expr)
}
else {
if closure_var_decl != '' {
g.write('${closure_var_decl} = ')
Expand Down
2 changes: 1 addition & 1 deletion vlib/v/gen/c/assign.v
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) {
var_type = g.table.find_or_register_array(g.unwrap_generic((val.args[0].expr as ast.AsCast).typ))
val_type = var_type
left.obj.typ = var_type
g.comptime.type_map['g.${left.name}.${left.obj.pos.pos}'] = var_type
g.type_resolver.type_map['g.${left.name}.${left.obj.pos.pos}'] = var_type
g.assign_ct_type = var_type
}
}
Expand Down
3 changes: 2 additions & 1 deletion vlib/v/gen/c/index.v
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ fn (mut g Gen) index_expr(node ast.IndexExpr) {
if node.index is ast.RangeExpr {
g.index_range_expr(node, node.index)
} else {
sym := g.table.final_sym(g.unwrap_generic(node.left_type))
left_type := g.type_resolver.get_type_or_default(node.left, node.left_type)
sym := g.table.final_sym(left_type)
if sym.kind == .array {
g.index_of_array(node, sym)
} else if sym.kind == .array_fixed {
Expand Down
7 changes: 7 additions & 0 deletions vlib/v/type_resolver/generic_resolver.v
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ pub fn (mut ct TypeResolver) unwrap_generic_expr(expr ast.Expr, default_typ ast.
default_typ
}
}
ast.AsCast {
return ct.resolver.unwrap_generic(expr.typ)
}
else {
return default_typ
}
Expand Down Expand Up @@ -71,6 +74,10 @@ pub fn (t &TypeResolver) is_generic_expr(node ast.Expr) bool {
// generic_var.property
t.is_generic_param_var(node.expr)
}
ast.AsCast {
// var as T
node.typ.has_flag(.generic)
}
else {
false
}
Expand Down

0 comments on commit a4c2a38

Please sign in to comment.