This commit is contained in:
Felipe Pena 2025-08-30 12:10:32 -03:00
parent 745b03963c
commit bb592afb98
3 changed files with 18 additions and 3 deletions

View file

@ -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('\tmemcpy(*(${styp}*)${c_name(node.val_var)}, (byte*)${cond_var}[${idx}], sizeof(${styp}));')
} else {
mut styp := g.styp(node.val_type)
styp := g.styp(node.val_type)
g.write('\t${styp} ${c_name(node.val_var)}')
}
if !is_fixed_array {

View file

@ -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 }
is_dump_expr := expr is ast.DumpExpr
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
&& (expr.return_type.is_ptr() || g.table.sym(expr.return_type).is_c_struct())
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) {
if typ.has_flag(.option_mut_param_t) {
g.write('/**/*')
g.write('*')
} else {
g.write('*(${g.styp(typ)}*)&')
}

View 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)]'
}