From 996bd41ce8efc45bbaa9564e77c906a31c89b250 Mon Sep 17 00:00:00 2001 From: yuyi Date: Tue, 1 Mar 2022 18:31:48 +0800 Subject: [PATCH] checker: simplify for smartcast in for_stmt() (#13619) --- vlib/v/checker/for.v | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) 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) } } }