1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

Revert "checker: fix autocast in complex if conditions 3 (#18710)"

This reverts commit e74723c1e7.
This commit is contained in:
Alexander Medvednikov 2023-06-29 21:37:11 +03:00
parent 357a4a00bf
commit cf323cd0ef
2 changed files with 3 additions and 43 deletions

View File

@ -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)
}

View File

@ -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
}
}