mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix expr in shared_array
(#11319)
This commit is contained in:
parent
5f90d5702e
commit
a85467eb0f
@ -447,7 +447,10 @@ fn (mut g Gen) gen_array_prepend(node ast.CallExpr) {
|
||||
}
|
||||
|
||||
fn (mut g Gen) gen_array_contains_method(left_type ast.Type) string {
|
||||
unwrap_left_type := g.unwrap_generic(left_type)
|
||||
mut unwrap_left_type := g.unwrap_generic(left_type)
|
||||
if unwrap_left_type.share() == .shared_t {
|
||||
unwrap_left_type = unwrap_left_type.clear_flag(.shared_f)
|
||||
}
|
||||
mut left_sym := g.table.get_type_symbol(unwrap_left_type)
|
||||
left_final_sym := g.table.get_final_type_symbol(unwrap_left_type)
|
||||
mut left_type_str := g.typ(unwrap_left_type).replace('*', '')
|
||||
@ -502,10 +505,13 @@ fn (mut g Gen) gen_array_contains_method(left_type ast.Type) string {
|
||||
fn (mut g Gen) gen_array_contains(node ast.CallExpr) {
|
||||
fn_name := g.gen_array_contains_method(node.left_type)
|
||||
g.write('${fn_name}(')
|
||||
if node.left_type.is_ptr() {
|
||||
if node.left_type.is_ptr() && node.left_type.share() != .shared_t {
|
||||
g.write('*')
|
||||
}
|
||||
g.expr(node.left)
|
||||
if node.left_type.share() == .shared_t {
|
||||
g.write('->val')
|
||||
}
|
||||
g.write(', ')
|
||||
g.expr(node.args[0].expr)
|
||||
g.write(')')
|
||||
|
@ -328,10 +328,13 @@ fn (mut g Gen) infix_expr_in_op(node ast.InfixExpr) {
|
||||
}
|
||||
fn_name := g.gen_array_contains_method(node.right_type)
|
||||
g.write('(${fn_name}(')
|
||||
if right.typ.is_ptr() {
|
||||
if right.typ.is_ptr() && right.typ.share() != .shared_t {
|
||||
g.write('*')
|
||||
}
|
||||
g.expr(node.right)
|
||||
if right.typ.share() == .shared_t {
|
||||
g.write('->val')
|
||||
}
|
||||
g.write(', ')
|
||||
g.expr(node.left)
|
||||
g.write('))')
|
||||
|
8
vlib/v/tests/shared_in_test.v
Normal file
8
vlib/v/tests/shared_in_test.v
Normal file
@ -0,0 +1,8 @@
|
||||
fn test_shared_in() {
|
||||
shared a := [1, 3, 7, 3]
|
||||
assert 1 in a
|
||||
assert 0 !in a
|
||||
assert 7 in a
|
||||
assert 3 in a
|
||||
assert 1238941 !in a
|
||||
}
|
Loading…
Reference in New Issue
Block a user