mirror of
https://github.com/vlang/v.git
synced 2025-09-17 03:17:25 -04:00
cgen: fix assert checking fn option ret with none
(#21726)
This commit is contained in:
parent
a36c0d8315
commit
fd384dff48
@ -2045,8 +2045,10 @@ fn (mut g Gen) expr_with_tmp_var(expr ast.Expr, expr_typ ast.Type, ret_typ ast.T
|
||||
}
|
||||
} else {
|
||||
simple_assign =
|
||||
(expr is ast.SelectorExpr || (expr is ast.Ident && !expr.is_auto_heap()))
|
||||
&& ret_typ.is_ptr() && expr_typ.is_ptr() && expr_typ.has_flag(.option)
|
||||
((expr is ast.SelectorExpr || (expr is ast.Ident && !expr.is_auto_heap()))
|
||||
&& ret_typ.is_ptr() && expr_typ.is_ptr() && expr_typ.has_flag(.option))
|
||||
|| (expr_typ == ret_typ && !(expr_typ.has_option_or_result()
|
||||
&& (expr_typ.is_ptr() || expr is ast.LambdaExpr)))
|
||||
// option ptr assignment simplification
|
||||
if simple_assign {
|
||||
g.write('${tmp_var} = ')
|
||||
|
@ -22,4 +22,5 @@ fn (mut g Gen) gen_ctemp_var(tvar ast.CTempVar) {
|
||||
g.write('${styp} ${tvar.name} = ')
|
||||
g.expr(tvar.orig)
|
||||
g.writeln(';')
|
||||
g.set_current_pos_as_last_stmt_pos()
|
||||
}
|
||||
|
8
vlib/v/tests/assert_fn_ret_option_test.v
Normal file
8
vlib/v/tests/assert_fn_ret_option_test.v
Normal file
@ -0,0 +1,8 @@
|
||||
fn find_token_by_id() ?int {
|
||||
return none
|
||||
}
|
||||
|
||||
fn test_main() {
|
||||
assert find_token_by_id() == none
|
||||
println('done')
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user