1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix assigning optional of multi_return with heap (#16049)

This commit is contained in:
yuyi 2022-10-13 18:07:52 +08:00 committed by GitHub
parent 213a094680
commit bfbfe78366
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 3 deletions

View File

@ -529,9 +529,6 @@ fn (mut g Gen) gen_multi_return_assign(node &ast.AssignStmt, return_type ast.Typ
styp := if ident.name in g.defer_vars { '' } else { g.typ(node.left_types[i]) }
if node.op == .decl_assign {
g.write('$styp ')
if is_auto_heap {
g.write('*')
}
}
if lx.is_auto_deref_var() {
g.write('*')

View File

@ -0,0 +1,50 @@
struct Poss1 {}
struct Poss2 {}
type Possibilities = Poss1 | Poss2
// comment out this attribute to make error go away BUT now you need to remember to use &PossOwner everytime you create new instance :(
[heap]
pub struct PossOwner {
pub:
name string
details Possibilities
}
fn (t PossOwner) get_file(path string) ?(PossOwner, Poss1) {
match t.details {
Poss1 { return t, t.details }
else { return error('not a file') }
}
}
fn (item PossOwner) check() ?int {
assert item.name == 'x'
return 0
}
fn somefun() ?int {
t := PossOwner{
name: 'x'
details: Poss1{}
}
path_info, _ := t.get_file('') or {
println('NOTOK1')
return 1
}
_ := path_info.check() or {
println('NOTOK2')
return 2
}
return 0
}
fn test_assign_optional_of_multi_return_with_heap() {
somefun() or { return }
println('success')
}