mirror of
https://github.com/vlang/v.git
synced 2025-09-10 07:47:20 -04:00
parent
4a99b1ef2d
commit
0148914e47
@ -979,15 +979,18 @@ fn (mut g Gen) gen_array_contains(left_type ast.Type, left ast.Expr, right_type
|
||||
g.write('->val')
|
||||
}
|
||||
g.write(', ')
|
||||
if right.is_auto_deref_var() {
|
||||
g.write('*')
|
||||
}
|
||||
left_sym := g.table.final_sym(left_type)
|
||||
elem_typ := if left_sym.kind == .array {
|
||||
left_sym.array_info().elem_type
|
||||
} else {
|
||||
left_sym.array_fixed_info().elem_type
|
||||
}
|
||||
if right.is_auto_deref_var()
|
||||
|| (g.table.sym(elem_typ).kind !in [.interface_, .sum_type, .struct_] && right is ast.Ident
|
||||
&& right.info is ast.IdentVar
|
||||
&& g.table.sym(right.obj.typ).kind in [.interface_, .sum_type]) {
|
||||
g.write('*')
|
||||
}
|
||||
if g.table.sym(elem_typ).kind in [.interface_, .sum_type] {
|
||||
g.expr_with_cast(right, right_type, elem_typ)
|
||||
} else {
|
||||
|
@ -622,6 +622,10 @@ fn (mut g Gen) infix_expr_in_optimization(left ast.Expr, right ast.ArrayInit) {
|
||||
.string, .alias, .sum_type, .map, .interface_, .array, .struct_ {
|
||||
if elem_sym.kind == .string {
|
||||
g.write('string__eq(')
|
||||
if left.is_auto_deref_var() || (left is ast.Ident && left.info is ast.IdentVar
|
||||
&& g.table.sym(left.obj.typ).kind in [.interface_, .sum_type]) {
|
||||
g.write('*')
|
||||
}
|
||||
} else {
|
||||
ptr_typ := g.equality_fn(right.elem_type)
|
||||
if elem_sym.kind == .alias {
|
||||
|
@ -39,3 +39,37 @@ fn test_any_called_with_opt_bool_fn() ? {
|
||||
_ := [1, 2, 3].any(opt_bool_fn()?)
|
||||
assert true
|
||||
}
|
||||
|
||||
interface Args {}
|
||||
|
||||
const some_strings = ['one', 'two', 'three']
|
||||
|
||||
// For test `gen array contains method`
|
||||
fn test_array_contains_method_with_interface() {
|
||||
arg := Args('one')
|
||||
match arg {
|
||||
string {
|
||||
if arg in some_strings {
|
||||
assert true
|
||||
return
|
||||
}
|
||||
}
|
||||
else {}
|
||||
}
|
||||
assert false
|
||||
}
|
||||
|
||||
// For test `gen string_eq method`
|
||||
fn test_string_eq_method_with_interface() {
|
||||
arg := Args('three')
|
||||
match arg {
|
||||
string {
|
||||
if arg in ['one', 'two', 'three'] {
|
||||
assert true
|
||||
return
|
||||
}
|
||||
}
|
||||
else {}
|
||||
}
|
||||
assert false
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user