mirror of
https://github.com/vlang/v.git
synced 2025-09-11 16:36:20 -04:00
This commit is contained in:
parent
21e6c46ae8
commit
ccb93e677c
@ -7579,6 +7579,12 @@ fn (mut g Gen) as_cast(node ast.AsCast) {
|
|||||||
g.unwrap_option_type(node.expr.typ, '${node.expr.expr.name}.${node.expr.field_name}',
|
g.unwrap_option_type(node.expr.typ, '${node.expr.expr.name}.${node.expr.field_name}',
|
||||||
node.expr.expr.is_auto_heap())
|
node.expr.expr.is_auto_heap())
|
||||||
is_optional_ident_var = true
|
is_optional_ident_var = true
|
||||||
|
} else if node.expr.expr is ast.SelectorExpr && node.expr.typ.has_flag(.option) {
|
||||||
|
if node.expr.expr.expr is ast.Ident {
|
||||||
|
g.unwrap_option_type(node.expr.typ, '${node.expr.expr.expr.name}.${node.expr.expr.field_name}.${node.expr.field_name}',
|
||||||
|
node.expr.expr.expr.is_auto_heap())
|
||||||
|
is_optional_ident_var = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !is_optional_ident_var {
|
if !is_optional_ident_var {
|
||||||
|
18
vlib/v/tests/options/option_embed_field_test.v
Normal file
18
vlib/v/tests/options/option_embed_field_test.v
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
struct Foo {
|
||||||
|
optional_one ?string
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Bar {
|
||||||
|
foo Foo
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_main() {
|
||||||
|
b := Bar{Foo{
|
||||||
|
optional_one: 'hello world'
|
||||||
|
}}
|
||||||
|
println(b.foo.optional_one)
|
||||||
|
x := b.foo.optional_one as string
|
||||||
|
|
||||||
|
assert x == 'hello world'
|
||||||
|
assert (b.foo.optional_one as string) == 'hello world'
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user