Skip to content

Commit 996bd41

Browse files
authored
checker: simplify for smartcast in for_stmt() (#13619)
1 parent 3b6e122 commit 996bd41

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

vlib/v/checker/for.v

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -150,21 +150,11 @@ fn (mut c Checker) for_stmt(mut node ast.ForStmt) {
150150
c.error('non-bool used as for condition', node.pos)
151151
}
152152
if mut node.cond is ast.InfixExpr {
153-
infix := node.cond
154-
if infix.op == .key_is {
155-
if infix.right is ast.TypeNode && infix.left in [ast.Ident, ast.SelectorExpr] {
156-
is_variable := if mut infix.left is ast.Ident {
157-
infix.left.kind == .variable
158-
} else {
159-
true
160-
}
161-
left_type := c.expr(infix.left)
162-
left_sym := c.table.sym(left_type)
163-
if is_variable {
164-
if left_sym.kind in [.sum_type, .interface_] {
165-
c.smartcast(infix.left, infix.left_type, infix.right.typ, mut
166-
node.scope)
167-
}
153+
if node.cond.op == .key_is {
154+
if node.cond.right is ast.TypeNode && node.cond.left in [ast.Ident, ast.SelectorExpr] {
155+
if c.table.type_kind(node.cond.left_type) in [.sum_type, .interface_] {
156+
c.smartcast(node.cond.left, node.cond.left_type, node.cond.right_type, mut
157+
node.scope)
168158
}
169159
}
170160
}

0 commit comments

Comments
 (0)