mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix error for optional cast to interface (#13623)
This commit is contained in:
parent
6d57315aca
commit
7f8f571ed2
@ -2001,7 +2001,7 @@ fn (mut g Gen) call_cfn_for_casting_expr(fname string, expr ast.Expr, exp_is_ptr
|
||||
if !got_is_ptr {
|
||||
if !expr.is_lvalue()
|
||||
|| (expr is ast.Ident && (expr as ast.Ident).obj.is_simple_define_const()) {
|
||||
g.write('ADDR($got_styp, (')
|
||||
g.write('HEAP($got_styp, (')
|
||||
rparen_n += 2
|
||||
} else {
|
||||
g.write('&')
|
||||
|
40
vlib/v/tests/cast_optional_to_interface_test.v
Normal file
40
vlib/v/tests/cast_optional_to_interface_test.v
Normal file
@ -0,0 +1,40 @@
|
||||
[heap]
|
||||
struct Package {
|
||||
str string
|
||||
}
|
||||
|
||||
interface Parser {
|
||||
main &Package
|
||||
}
|
||||
|
||||
struct ParserV1 {
|
||||
mut:
|
||||
main &Package
|
||||
}
|
||||
|
||||
fn new_0_parser() ?ParserV1 {
|
||||
return ParserV1{
|
||||
main: &Package{
|
||||
str: 'test'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn new_parser() ?Parser {
|
||||
return Parser(new_0_parser() ?)
|
||||
}
|
||||
|
||||
struct Engine {
|
||||
parser Parser
|
||||
}
|
||||
|
||||
fn test_cast_optional_to_interface() ? {
|
||||
parser := new_parser() ?
|
||||
assert parser.main.str == 'test'
|
||||
eprintln(voidptr(parser.main))
|
||||
e := Engine{
|
||||
parser: parser
|
||||
}
|
||||
assert e.parser.main.str == 'test'
|
||||
eprintln(voidptr(e.parser.main))
|
||||
}
|
Loading…
Reference in New Issue
Block a user