cgen: fix codegen for result/option propagation out of fn context (fix #22961) (#22963)

This commit is contained in:
Felipe Pena 2024-11-24 20:15:04 -03:00 committed by GitHub
parent 5cd84d4565
commit 335357239a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 2 deletions

View File

@ -7332,7 +7332,7 @@ fn (mut g Gen) or_block(var_name string, or_block ast.OrExpr, return_type ast.Ty
// the deferred statements are generated.
g.write_defer_stmts()
// Now that option types are distinct we need a cast here
if g.fn_decl.return_type == ast.void_type {
if g.fn_decl == unsafe { nil } || g.fn_decl.return_type == ast.void_type {
g.writeln('\treturn;')
} else {
styp := g.styp(g.fn_decl.return_type)
@ -7360,7 +7360,7 @@ fn (mut g Gen) or_block(var_name string, or_block ast.OrExpr, return_type ast.Ty
// the deferred statements are generated.
g.write_defer_stmts()
// Now that option types are distinct we need a cast here
if g.fn_decl.return_type == ast.void_type {
if g.fn_decl == unsafe { nil } || g.fn_decl.return_type == ast.void_type {
g.writeln('\treturn;')
} else {
styp := g.styp(g.fn_decl.return_type).replace('*', '_ptr')

View File

@ -0,0 +1,16 @@
// mod.v
module mymod
import math.big
pub struct BigintRange {
pub mut:
start big.Integer
end big.Integer
}
pub const range = BigintRange{
start: big.integer_from_string('338288524927261089654018896841347694592')!
end: big.integer_from_string('338620831926207318622244848606417780735')!
}

View File

@ -0,0 +1,7 @@
// mod_test.v
module mymod
fn test_dummy() {
assert range != BigintRange{}
}