From b9a1f1426b2cb1ab76aeaaf515b790ecb64391f3 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Mon, 4 Nov 2024 20:02:37 -0300 Subject: [PATCH 1/3] fix --- vlib/v/gen/c/infix.v | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/vlib/v/gen/c/infix.v b/vlib/v/gen/c/infix.v index 13334cc67e4a31..b79847167f29fd 100644 --- a/vlib/v/gen/c/infix.v +++ b/vlib/v/gen/c/infix.v @@ -657,6 +657,7 @@ fn (mut g Gen) infix_expr_in_op(node ast.InfixExpr) { // and transform them in a series of equality comparison // i.e. `a in [1,2,3]` => `a == 1 || a == 2 || a == 3` fn (mut g Gen) infix_expr_in_optimization(left ast.Expr, left_type ast.Type, right ast.ArrayInit) { + tmp_var := if left is ast.CallExpr { g.new_tmp_var() } else { '' } mut elem_sym := g.table.sym(right.elem_type) left_parent_idx := g.table.sym(left_type).parent_idx for i, array_expr in right.exprs { @@ -719,13 +720,39 @@ fn (mut g Gen) infix_expr_in_optimization(left ast.Expr, left_type ast.Type, rig g.write('${ptr_typ}_struct_eq(') } } - g.expr(left) + if left is ast.CallExpr { + if i == 0 { + line := g.go_before_last_stmt().trim_space() + g.empty_line = true + g.write('${g.styp(left.return_type)} ${tmp_var} = ') + g.expr(left) + g.writeln(';') + g.write2(line, tmp_var) + } else { + g.write(tmp_var) + } + } else { + g.expr(left) + } g.write(', ') g.expr(array_expr) g.write(')') } else { // works in function kind - g.expr(left) + if left is ast.CallExpr { + if i == 0 { + line := g.go_before_last_stmt().trim_space() + g.empty_line = true + g.write('${g.styp(left.return_type)} ${tmp_var} = ') + g.expr(left) + g.writeln(';') + g.write2(line, tmp_var) + } else { + g.write(tmp_var) + } + } else { + g.expr(left) + } g.write(' == ') g.expr(array_expr) } From 6dc930946201616eb854ef28553ab7735ac4e084 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Mon, 4 Nov 2024 20:02:56 -0300 Subject: [PATCH 2/3] test --- vlib/v/slow_tests/inout/in_expr_callexpr.out | 4 ++++ vlib/v/slow_tests/inout/in_expr_callexpr.vv | 14 ++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 vlib/v/slow_tests/inout/in_expr_callexpr.out create mode 100644 vlib/v/slow_tests/inout/in_expr_callexpr.vv diff --git a/vlib/v/slow_tests/inout/in_expr_callexpr.out b/vlib/v/slow_tests/inout/in_expr_callexpr.out new file mode 100644 index 00000000000000..8e9950d1ab9fb0 --- /dev/null +++ b/vlib/v/slow_tests/inout/in_expr_callexpr.out @@ -0,0 +1,4 @@ +t +true +t2 +true diff --git a/vlib/v/slow_tests/inout/in_expr_callexpr.vv b/vlib/v/slow_tests/inout/in_expr_callexpr.vv new file mode 100644 index 00000000000000..ce2e227218e5a1 --- /dev/null +++ b/vlib/v/slow_tests/inout/in_expr_callexpr.vv @@ -0,0 +1,14 @@ +fn t() bool { + println('${@FN}') + return true +} + +fn t2() int { + println('${@FN}') + return 2 +} + +fn main() { + println(t() in [false, true]) + println(t2() in [0, 1, 2, 3, 4, 5]) +} From 45bef6dc8bffffab7189756c5edcbd49304ac1b2 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Tue, 5 Nov 2024 09:27:24 -0300 Subject: [PATCH 3/3] fix test --- vlib/v/slow_tests/inout/in_expr_callexpr.vv | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vlib/v/slow_tests/inout/in_expr_callexpr.vv b/vlib/v/slow_tests/inout/in_expr_callexpr.vv index ce2e227218e5a1..b64c098d32402e 100644 --- a/vlib/v/slow_tests/inout/in_expr_callexpr.vv +++ b/vlib/v/slow_tests/inout/in_expr_callexpr.vv @@ -1,10 +1,10 @@ fn t() bool { - println('${@FN}') + println(@FN) return true } fn t2() int { - println('${@FN}') + println(@FN) return 2 }