Skip to content

Commit 0ed2e18

Browse files
committed
fix: initialize error object in or_block (fix vlang#24529)
1 parent 22c327f commit 0ed2e18

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

vlib/v/gen/c/cgen.v

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7087,7 +7087,13 @@ fn (mut g Gen) or_block(var_name string, or_block ast.OrExpr, return_type ast.Ty
70877087
} else {
70887088
styp := g.styp(g.fn_decl.return_type)
70897089
err_obj := g.new_tmp_var()
7090-
g.writeln2('\t${styp} ${err_obj};', '\tmemcpy(&${err_obj}, &${cvar_name}, sizeof(${result_name}));')
7090+
g.writeln('\t${styp} ${err_obj} = {0};')
7091+
if g.fn_decl.return_type.has_flag(.result) {
7092+
g.writeln('\t${err_obj}.is_error = true;')
7093+
} else if g.fn_decl.return_type.has_flag(.option) {
7094+
g.writeln('\t${err_obj}.state = 2;')
7095+
}
7096+
g.writeln('\t${err_obj}.err = ${cvar_name}${tmp_op}err;')
70917097
g.writeln('\treturn ${err_obj};')
70927098
}
70937099
}

0 commit comments

Comments
 (0)