mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix embed struct with sumtype field (#17823)
This commit is contained in:
parent
214f72ba03
commit
b40aa4ffa9
@ -3491,7 +3491,7 @@ fn (mut g Gen) selector_expr(node ast.SelectorExpr) {
|
||||
}
|
||||
mut sum_type_deref_field := ''
|
||||
mut sum_type_dot := '.'
|
||||
if f := g.table.find_field(sym, node.field_name) {
|
||||
if f := g.table.find_field_with_embeds(sym, node.field_name) {
|
||||
field_sym := g.table.sym(f.typ)
|
||||
if field_sym.kind in [.sum_type, .interface_] {
|
||||
if !prevent_sum_type_unwrapping_once {
|
||||
|
28
vlib/v/tests/embed_struct_with_sumtype_field_test.v
Normal file
28
vlib/v/tests/embed_struct_with_sumtype_field_test.v
Normal file
@ -0,0 +1,28 @@
|
||||
type Prefix = [2]string | string
|
||||
|
||||
struct FooStruct {
|
||||
prefix Prefix
|
||||
}
|
||||
|
||||
struct BarStruct {
|
||||
FooStruct
|
||||
}
|
||||
|
||||
fn (b BarStruct) print_prefix() string {
|
||||
if b.prefix is [2]string {
|
||||
eprint(b.prefix[0])
|
||||
return b.prefix[0]
|
||||
} else if b.prefix is string {
|
||||
eprint(b.prefix)
|
||||
return b.prefix
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
fn test_embed_struct_with_sumtype_field() {
|
||||
b := BarStruct{
|
||||
prefix: ['abc', 'bcd']!
|
||||
}
|
||||
ret := b.print_prefix()
|
||||
assert ret == 'abc'
|
||||
}
|
Loading…
Reference in New Issue
Block a user