checker: correct pos for type error of `if v is interface` (#9080)

pull/9084/head
zakuro 2021-03-03 16:23:39 +09:00 committed by GitHub
parent 8a0b5bad94
commit c74fa9e471
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -4824,7 +4824,7 @@ pub fn (mut c Checker) if_expr(mut node ast.IfExpr) table.Type {
left_sym := c.table.get_type_symbol(infix.left_type) left_sym := c.table.get_type_symbol(infix.left_type)
expr_type := c.expr(infix.left) expr_type := c.expr(infix.left)
if left_sym.kind == .interface_ { if left_sym.kind == .interface_ {
c.type_implements(right_expr.typ, expr_type, branch.pos) c.type_implements(right_expr.typ, expr_type, branch.cond.position())
} else if !c.check_types(right_expr.typ, expr_type) { } else if !c.check_types(right_expr.typ, expr_type) {
expect_str := c.table.type_to_str(right_expr.typ) expect_str := c.table.type_to_str(right_expr.typ)
expr_str := c.table.type_to_str(expr_type) expr_str := c.table.type_to_str(expr_type)

View File

@ -5,10 +5,10 @@ vlib/v/checker/tests/is_type_invalid.vv:14:12: error: `IoS` has no variant `byte
| ~~ | ~~
15 | println('not cool') 15 | println('not cool')
16 | } 16 | }
vlib/v/checker/tests/is_type_invalid.vv:18:2: error: `Cat` doesn't implement method `speak` of interface `Animal` vlib/v/checker/tests/is_type_invalid.vv:18:5: error: `Cat` doesn't implement method `speak` of interface `Animal`
16 | } 16 | }
17 | a := Animal(Dog{}) 17 | a := Animal(Dog{})
18 | if a is Cat { 18 | if a is Cat {
| ~~~~~~~~~~~ | ~~~~~~~~
19 | println('not cool either') 19 | println('not cool either')
20 | } 20 | }