checker: correct pos for type error of `if v is interface` (#9080)
parent
8a0b5bad94
commit
c74fa9e471
|
@ -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)
|
||||
expr_type := c.expr(infix.left)
|
||||
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) {
|
||||
expect_str := c.table.type_to_str(right_expr.typ)
|
||||
expr_str := c.table.type_to_str(expr_type)
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
vlib/v/checker/tests/is_type_invalid.vv:14:12: error: `IoS` has no variant `byte`
|
||||
12 |
|
||||
12 |
|
||||
13 | fn main() {
|
||||
14 | if IoS(1) is byte {
|
||||
| ~~
|
||||
15 | println('not cool')
|
||||
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 | }
|
||||
17 | a := Animal(Dog{})
|
||||
18 | if a is Cat {
|
||||
| ~~~~~~~~~~~
|
||||
| ~~~~~~~~
|
||||
19 | println('not cool either')
|
||||
20 | }
|
||||
|
|
Loading…
Reference in New Issue