diff --git a/vlib/v/checker/for.v b/vlib/v/checker/for.v index ce7280a417..d4e7993a36 100644 --- a/vlib/v/checker/for.v +++ b/vlib/v/checker/for.v @@ -150,21 +150,11 @@ fn (mut c Checker) for_stmt(mut node ast.ForStmt) { c.error('non-bool used as for condition', node.pos) } if mut node.cond is ast.InfixExpr { - infix := node.cond - if infix.op == .key_is { - if infix.right is ast.TypeNode && infix.left in [ast.Ident, ast.SelectorExpr] { - is_variable := if mut infix.left is ast.Ident { - infix.left.kind == .variable - } 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) - } + if node.cond.op == .key_is { + if node.cond.right is ast.TypeNode && node.cond.left in [ast.Ident, ast.SelectorExpr] { + if c.table.type_kind(node.cond.left_type) in [.sum_type, .interface_] { + c.smartcast(node.cond.left, node.cond.left_type, node.cond.right_type, mut + node.scope) } } }