mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: simplify for smartcast in for_stmt() (#13619)
This commit is contained in:
parent
3b6e122d9d
commit
996bd41ce8
@ -150,21 +150,11 @@ fn (mut c Checker) for_stmt(mut node ast.ForStmt) {
|
|||||||
c.error('non-bool used as for condition', node.pos)
|
c.error('non-bool used as for condition', node.pos)
|
||||||
}
|
}
|
||||||
if mut node.cond is ast.InfixExpr {
|
if mut node.cond is ast.InfixExpr {
|
||||||
infix := node.cond
|
if node.cond.op == .key_is {
|
||||||
if infix.op == .key_is {
|
if node.cond.right is ast.TypeNode && node.cond.left in [ast.Ident, ast.SelectorExpr] {
|
||||||
if infix.right is ast.TypeNode && infix.left in [ast.Ident, ast.SelectorExpr] {
|
if c.table.type_kind(node.cond.left_type) in [.sum_type, .interface_] {
|
||||||
is_variable := if mut infix.left is ast.Ident {
|
c.smartcast(node.cond.left, node.cond.left_type, node.cond.right_type, mut
|
||||||
infix.left.kind == .variable
|
node.scope)
|
||||||
} else {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
left_type := c.expr(infix.left)
|
|
||||||
left_sym := c.table.sym(left_type)
|
|
||||||
if is_variable {
|
|
||||||
if left_sym.kind in [.sum_type, .interface_] {
|
|
||||||
c.smartcast(infix.left, infix.left_type, infix.right.typ, mut
|
|
||||||
node.scope)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user