mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parent
5e5c78ed37
commit
2ab861ef89
@ -1557,6 +1557,7 @@ fn (mut g Gen) ref_or_deref_arg(arg ast.CallArg, expected_type ast.Type, lang as
|
|||||||
g.checker_bug('ref_or_deref_arg expected_type is 0', arg.pos)
|
g.checker_bug('ref_or_deref_arg expected_type is 0', arg.pos)
|
||||||
}
|
}
|
||||||
exp_sym := g.table.get_type_symbol(expected_type)
|
exp_sym := g.table.get_type_symbol(expected_type)
|
||||||
|
arg_typ := g.unwrap_generic(arg.typ)
|
||||||
mut needs_closing := false
|
mut needs_closing := false
|
||||||
if arg.is_mut && !arg_is_ptr {
|
if arg.is_mut && !arg_is_ptr {
|
||||||
g.write('&/*mut*/')
|
g.write('&/*mut*/')
|
||||||
@ -1578,10 +1579,10 @@ fn (mut g Gen) ref_or_deref_arg(arg ast.CallArg, expected_type ast.Type, lang as
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !g.is_json_fn {
|
if !g.is_json_fn {
|
||||||
if arg.typ == 0 {
|
if arg_typ == 0 {
|
||||||
g.checker_bug('ref_or_deref_arg arg.typ is 0', arg.pos)
|
g.checker_bug('ref_or_deref_arg arg.typ is 0', arg.pos)
|
||||||
}
|
}
|
||||||
arg_typ_sym := g.table.get_type_symbol(arg.typ)
|
arg_typ_sym := g.table.get_type_symbol(arg_typ)
|
||||||
expected_deref_type := if expected_type.is_ptr() {
|
expected_deref_type := if expected_type.is_ptr() {
|
||||||
expected_type.deref()
|
expected_type.deref()
|
||||||
} else {
|
} else {
|
||||||
@ -1606,7 +1607,7 @@ fn (mut g Gen) ref_or_deref_arg(arg ast.CallArg, expected_type ast.Type, lang as
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if arg.typ.has_flag(.shared_f) && !expected_type.has_flag(.shared_f) {
|
} else if arg_typ.has_flag(.shared_f) && !expected_type.has_flag(.shared_f) {
|
||||||
if expected_type.is_ptr() {
|
if expected_type.is_ptr() {
|
||||||
g.write('&')
|
g.write('&')
|
||||||
}
|
}
|
||||||
@ -1614,7 +1615,7 @@ fn (mut g Gen) ref_or_deref_arg(arg ast.CallArg, expected_type ast.Type, lang as
|
|||||||
g.write('->val')
|
g.write('->val')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
g.expr_with_cast(arg.expr, arg.typ, expected_type)
|
g.expr_with_cast(arg.expr, arg_typ, expected_type)
|
||||||
if needs_closing {
|
if needs_closing {
|
||||||
g.write(')')
|
g.write(')')
|
||||||
}
|
}
|
||||||
|
36
vlib/v/tests/generics_array_of_interface_method_call_test.v
Normal file
36
vlib/v/tests/generics_array_of_interface_method_call_test.v
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
struct Array<T> {
|
||||||
|
pub mut:
|
||||||
|
elements []T
|
||||||
|
}
|
||||||
|
|
||||||
|
struct String {
|
||||||
|
str string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IObject {
|
||||||
|
equals(IObject) bool
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn (s1 String) equals(s2 IObject) bool {
|
||||||
|
if s2 is String {
|
||||||
|
return s1.str == s2.str
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn (mut m Array<T>) contains(e T) bool {
|
||||||
|
for mut element in m.elements {
|
||||||
|
if element.equals(e) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_generic_array_of_interface_method_call() {
|
||||||
|
s := String{'hello'}
|
||||||
|
mut a := Array<IObject>{[s]}
|
||||||
|
ret := a.contains(IObject(s))
|
||||||
|
println(ret)
|
||||||
|
assert ret
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user