Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Dec 4, 2023
1 parent d9e9c71 commit de6fa1e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 6 deletions.
24 changes: 18 additions & 6 deletions vlib/v/gen/c/fn.v
Original file line number Diff line number Diff line change
Expand Up @@ -1073,9 +1073,21 @@ fn (mut g Gen) change_comptime_args(func ast.Fn, mut node_ ast.CallExpr, concret
mut ctyp := g.get_comptime_var_type(call_arg.expr)
if ctyp != ast.void_type {
arg_sym := g.table.sym(ctyp)
if arg_sym.kind == .array && param_typ.has_flag(.generic)
&& g.table.final_sym(param_typ).kind == .array {
ctyp = (arg_sym.info as ast.Array).elem_type
param_sym := g.table.final_sym(param_typ)
if arg_sym.info is ast.Array && param_sym.kind == .array {
ctyp = arg_sym.info.elem_type
} else if arg_sym.info is ast.Map && param_sym.info is ast.Map {
if call_arg.expr.obj.ct_type_var == .value_var {
ctyp = arg_sym.info.value_type
if param_sym.info.value_type.nr_muls() > 0 && ctyp.nr_muls() > 0 {
ctyp = ctyp.set_nr_muls(0)
}
} else if call_arg.expr.obj.ct_type_var == .key_var {
ctyp = arg_sym.info.key_type
if param_sym.info.key_type.nr_muls() > 0 && ctyp.nr_muls() > 0 {
ctyp = ctyp.set_nr_muls(0)
}
}
}
comptime_args[i] = ctyp
}
Expand Down Expand Up @@ -1113,9 +1125,9 @@ fn (mut g Gen) change_comptime_args(func ast.Fn, mut node_ ast.CallExpr, concret
}
}
} else if arg_sym.kind == .any {
mut cparam_type_sym := g.table.sym(g.unwrap_generic(ctyp))
if param_typ_sym.kind == .array && cparam_type_sym.kind == .array {
ctyp = (cparam_type_sym.info as ast.Array).elem_type
cparam_type_sym := g.table.sym(g.unwrap_generic(ctyp))
if param_typ_sym.kind == .array && cparam_type_sym.info is ast.Array {
ctyp = cparam_type_sym.info.elem_type
comptime_args[i] = ctyp
} else {
if node_.args[i].expr.is_auto_deref_var() {
Expand Down
33 changes: 33 additions & 0 deletions vlib/v/tests/comptime_for_map_arg_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
fn merged[K, V](a map[K]V, b map[K]V) map[K]V {
mut o := a.clone()
for k, v in b {
$if V is $map {
o[k] = merged(o[k], v)
} $else {
o[k] = v
}
}
return o
}

fn test_main() {
a := {
'aa': {
'11': 1
}
}
b := {
'bb': {
'22': 2
}
}
c := merged(a, b)
assert c == {
'aa': {
'11': 1
}
'bb': {
'22': 2
}
}
}

0 comments on commit de6fa1e

Please sign in to comment.