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

cgen: fix missing aggregate rec_type (#17335)

This commit is contained in:
Felipe Pena 2023-02-16 12:36:16 -03:00 committed by GitHub
parent 936bced29e
commit e066d1d3df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 0 deletions

View File

@ -952,6 +952,19 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
else {}
}
}
if node.from_embed_types.len == 0 && node.left is ast.Ident {
if node.left.obj is ast.Var {
if node.left.obj.smartcasts.len > 0 {
unwrapped_rec_type = g.unwrap_generic(node.left.obj.smartcasts.last())
cast_sym := g.table.sym(unwrapped_rec_type)
if cast_sym.info is ast.Aggregate {
unwrapped_rec_type = cast_sym.info.types[g.aggregate_type_idx]
}
}
}
}
if g.inside_comptime_for_field {
mut node_ := unsafe { node }
comptime_args = g.change_comptime_args(mut node_)

View File

@ -0,0 +1,27 @@
type SumType = AA | BB
struct AA {}
struct BB {}
fn (a &AA) foo() int {
println('AA.foo()')
return 200
}
fn (b &BB) foo() int {
println('BB.foo()')
return 100
}
fn test_main() {
x := SumType(BB{})
match x {
AA, BB {
ret := x.foo()
assert ret == 100
return
}
}
assert false
}