mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
fix
This commit is contained in:
parent
745b03963c
commit
bb592afb98
3 changed files with 18 additions and 3 deletions
|
@ -322,7 +322,7 @@ fn (mut g Gen) for_in_stmt(node_ ast.ForInStmt) {
|
||||||
g.writeln('\t${styp} ${c_name(node.val_var)};')
|
g.writeln('\t${styp} ${c_name(node.val_var)};')
|
||||||
g.writeln('\tmemcpy(*(${styp}*)${c_name(node.val_var)}, (byte*)${cond_var}[${idx}], sizeof(${styp}));')
|
g.writeln('\tmemcpy(*(${styp}*)${c_name(node.val_var)}, (byte*)${cond_var}[${idx}], sizeof(${styp}));')
|
||||||
} else {
|
} else {
|
||||||
mut styp := g.styp(node.val_type)
|
styp := g.styp(node.val_type)
|
||||||
g.write('\t${styp} ${c_name(node.val_var)}')
|
g.write('\t${styp} ${c_name(node.val_var)}')
|
||||||
}
|
}
|
||||||
if !is_fixed_array {
|
if !is_fixed_array {
|
||||||
|
|
|
@ -120,7 +120,7 @@ fn (mut g Gen) gen_expr_to_string(expr ast.Expr, etype ast.Type) {
|
||||||
exp_typ := if unwrap_option { typ.clear_flag(.option) } else { typ }
|
exp_typ := if unwrap_option { typ.clear_flag(.option) } else { typ }
|
||||||
is_dump_expr := expr is ast.DumpExpr
|
is_dump_expr := expr is ast.DumpExpr
|
||||||
is_var_mut := expr.is_auto_deref_var()
|
is_var_mut := expr.is_auto_deref_var()
|
||||||
mut str_fn_name := g.get_str_fn(exp_typ)
|
str_fn_name := g.get_str_fn(exp_typ)
|
||||||
temp_var_needed := expr is ast.CallExpr
|
temp_var_needed := expr is ast.CallExpr
|
||||||
&& (expr.return_type.is_ptr() || g.table.sym(expr.return_type).is_c_struct())
|
&& (expr.return_type.is_ptr() || g.table.sym(expr.return_type).is_c_struct())
|
||||||
mut tmp_var := ''
|
mut tmp_var := ''
|
||||||
|
@ -171,7 +171,7 @@ fn (mut g Gen) gen_expr_to_string(expr ast.Expr, etype ast.Type) {
|
||||||
}
|
}
|
||||||
} else if is_ptr && typ.has_flag(.option) {
|
} else if is_ptr && typ.has_flag(.option) {
|
||||||
if typ.has_flag(.option_mut_param_t) {
|
if typ.has_flag(.option_mut_param_t) {
|
||||||
g.write('/**/*')
|
g.write('*')
|
||||||
} else {
|
} else {
|
||||||
g.write('*(${g.styp(typ)}*)&')
|
g.write('*(${g.styp(typ)}*)&')
|
||||||
}
|
}
|
||||||
|
|
15
vlib/v/tests/options/option_for_mut_test.v
Normal file
15
vlib/v/tests/options/option_for_mut_test.v
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
module main
|
||||||
|
|
||||||
|
fn test_main() {
|
||||||
|
mut data := [3]?int{}
|
||||||
|
|
||||||
|
for mut d in data {
|
||||||
|
d = ?int(1)
|
||||||
|
assert '${d}' == 'Option(1)'
|
||||||
|
}
|
||||||
|
|
||||||
|
for i in 0 .. data.len {
|
||||||
|
data[i] = ?int(3)
|
||||||
|
}
|
||||||
|
assert '${data}' == '[Option(3), Option(3), Option(3)]'
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue