From cf323cd0eff1dae3e6ebcf5e2a652eeed9d8ff01 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 29 Jun 2023 21:37:11 +0300 Subject: [PATCH] Revert "checker: fix autocast in complex if conditions 3 (#18710)" This reverts commit e74723c1e76d9acb3f0a0266a9c7670d4c9bfed1. --- vlib/v/checker/infix.v | 14 ++-------- vlib/v/tests/autocast_in_if_conds_4_test.v | 32 ---------------------- 2 files changed, 3 insertions(+), 43 deletions(-) delete mode 100644 vlib/v/tests/autocast_in_if_conds_4_test.v diff --git a/vlib/v/checker/infix.v b/vlib/v/checker/infix.v index 2b29c15330..6a7088c3de 100644 --- a/vlib/v/checker/infix.v +++ b/vlib/v/checker/infix.v @@ -24,6 +24,7 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type { to_type := c.expr(left_node.right.right) c.autocast_in_if_conds(mut node.right, left_node.right.left, from_type, to_type) + break } } if left_node.op == .key_is { @@ -830,18 +831,8 @@ fn (mut c Checker) invalid_operator_error(op token.Kind, left_type ast.Type, rig } // `if node is ast.Ident && node.is_mut { ... }` -> `if node is ast.Ident && (node as ast.Ident).is_mut { ... }` -fn (mut c Checker) autocast_in_if_conds(mut right_ ast.Expr, from_expr ast.Expr, from_type ast.Type, to_type ast.Type) { - mut right := right_ +fn (mut c Checker) autocast_in_if_conds(mut right ast.Expr, from_expr ast.Expr, from_type ast.Type, to_type ast.Type) { match mut right { - ast.Ident { - if right.name == from_expr.str() { - right_ = ast.AsCast{ - typ: to_type - expr: from_expr - expr_type: from_type - } - } - } ast.SelectorExpr { if right.expr.str() == from_expr.str() { right.expr = ast.ParExpr{ @@ -872,6 +863,7 @@ fn (mut c Checker) autocast_in_if_conds(mut right_ ast.Expr, from_expr ast.Expr, } } } + c.autocast_in_if_conds(mut right.left, from_expr, from_type, to_type) for mut arg in right.args { c.autocast_in_if_conds(mut arg.expr, from_expr, from_type, to_type) } diff --git a/vlib/v/tests/autocast_in_if_conds_4_test.v b/vlib/v/tests/autocast_in_if_conds_4_test.v deleted file mode 100644 index 6b83306f0e..0000000000 --- a/vlib/v/tests/autocast_in_if_conds_4_test.v +++ /dev/null @@ -1,32 +0,0 @@ -type MySumType = S1 | S2 - -struct Info { - name string -} - -struct S1 { - is_info bool - info Info -} - -struct S2 { - field2 string -} - -fn get_name(s1 S1) string { - return s1.info.name -} - -fn test_autocast_in_if_conds() { - s := MySumType(S1{ - is_info: false - info: Info{'foo'} - }) - - if s is S1 && !s.is_info && get_name(s) == 'foo' { - println('ok') - assert true - } else { - assert false - } -}