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:
parent
936bced29e
commit
e066d1d3df
@ -952,6 +952,19 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
|
|||||||
else {}
|
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 {
|
if g.inside_comptime_for_field {
|
||||||
mut node_ := unsafe { node }
|
mut node_ := unsafe { node }
|
||||||
comptime_args = g.change_comptime_args(mut node_)
|
comptime_args = g.change_comptime_args(mut node_)
|
||||||
|
27
vlib/v/tests/method_call_on_aggregate_test.v
Normal file
27
vlib/v/tests/method_call_on_aggregate_test.v
Normal 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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user