mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parent
91874f3244
commit
8b37694760
@ -1157,6 +1157,10 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
|
|||||||
typ_sym = g.table.sym(unwrapped_rec_type)
|
typ_sym = g.table.sym(unwrapped_rec_type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if node.from_embed_types.len > 0 && !typ_sym.has_method(node.name) {
|
||||||
|
unwrapped_rec_type = node.from_embed_types.last()
|
||||||
|
typ_sym = g.table.sym(unwrapped_rec_type)
|
||||||
|
}
|
||||||
rec_cc_type := g.cc_type(unwrapped_rec_type, false)
|
rec_cc_type := g.cc_type(unwrapped_rec_type, false)
|
||||||
mut receiver_type_name := util.no_dots(rec_cc_type)
|
mut receiver_type_name := util.no_dots(rec_cc_type)
|
||||||
if typ_sym.kind == .interface_ && (typ_sym.info as ast.Interface).defines_method(node.name) {
|
if typ_sym.kind == .interface_ && (typ_sym.info as ast.Interface).defines_method(node.name) {
|
||||||
|
32
vlib/v/tests/generics_method_on_embed_struct_test.v
Normal file
32
vlib/v/tests/generics_method_on_embed_struct_test.v
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
struct Context {}
|
||||||
|
|
||||||
|
pub fn (mut ctx Context) default_route() string {
|
||||||
|
println('from Context')
|
||||||
|
return 'from Context'
|
||||||
|
}
|
||||||
|
|
||||||
|
struct App {
|
||||||
|
Context
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Other {
|
||||||
|
Context
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn (mut app Other) default_route() string {
|
||||||
|
println('from Other')
|
||||||
|
return 'from Other'
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_generic_method_on_nested_struct() {
|
||||||
|
mut app := &App{}
|
||||||
|
ret1 := call_generic(mut app)
|
||||||
|
assert ret1 == 'from Context'
|
||||||
|
mut other := &Other{}
|
||||||
|
ret2 := call_generic(mut other)
|
||||||
|
assert ret2 == 'from Other'
|
||||||
|
}
|
||||||
|
|
||||||
|
fn call_generic[T](mut app T) string {
|
||||||
|
return app.default_route()
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user