cgen: return interface fix

pull/5136/head
Alexander Medvednikov 2020-05-30 20:18:03 +02:00
parent 1ca7a607d3
commit 905f844b16
2 changed files with 7 additions and 2 deletions

View File

@ -2314,11 +2314,12 @@ fn (mut g Gen) return_statement(node ast.Return) {
g.writeln(' }, sizeof($styp));')
return
}
if sym.kind == .interface_ {
cast_interface := sym.kind == .interface_ && node.types[0] != g.fn_decl.return_type
if cast_interface {
g.interface_call(node.types[0], g.fn_decl.return_type)
}
g.expr_with_cast(node.exprs[0], node.types[0], g.fn_decl.return_type)
if sym.kind == .interface_ {
if cast_interface {
g.write(')')
}
}

View File

@ -243,3 +243,7 @@ fn new_animal() Animal {
dog := Dog{}
return dog
}
fn new_animal2() Animal {
return new_animal()
}