checker: fix `T is int`

pull/10081/head
Alexander Medvednikov 2021-05-11 10:28:11 +03:00
parent d088c4cee3
commit 0bc80951e3
2 changed files with 4 additions and 2 deletions

View File

@ -5982,7 +5982,8 @@ fn (mut c Checker) comp_if_branch(cond ast.Expr, pos token.Position) bool {
type_node := cond.right as ast.TypeNode
sym := c.table.get_type_symbol(type_node.typ)
if sym.kind != .interface_ {
c.error('`$sym.name` is not an interface', cond.right.position())
c.expr(cond.left)
// c.error('`$sym.name` is not an interface', cond.right.position())
}
return false
} else if cond.left is ast.SelectorExpr || cond.left is ast.TypeNode {

View File

@ -319,7 +319,8 @@ fn (mut g Gen) comp_if_cond(cond ast.Expr) bool {
got_type := (cond.right as ast.TypeNode).typ
// Handle `$if x is Interface {`
// mut matches_interface := 'false'
if left is ast.TypeNode && cond.right is ast.TypeNode {
if left is ast.TypeNode && cond.right is ast.TypeNode
&& g.table.get_type_symbol(got_type).kind == .interface_ {
// `$if Foo is Interface {`
interface_sym := g.table.get_type_symbol(got_type)
if interface_sym.info is ast.Interface {