mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
interfaces: fix is
This commit is contained in:
parent
b3f2c629c6
commit
bec3e07635
@ -3614,6 +3614,11 @@ fn (mut g Gen) is_expr(node ast.InfixExpr) {
|
||||
sym := g.table.get_type_symbol(node.left_type)
|
||||
if sym.kind == .interface_ {
|
||||
g.write('_interface_idx == ')
|
||||
// `_Animal_Dog_index`
|
||||
sub_type := node.right as ast.Type
|
||||
sub_sym := g.table.get_type_symbol(sub_type.typ)
|
||||
g.write('_${sym.name}_${sub_sym.name}_index')
|
||||
return
|
||||
} else if sym.kind == .sum_type {
|
||||
g.write('typ == ')
|
||||
}
|
||||
|
@ -225,3 +225,16 @@ fn test_interface_ptr_array() {
|
||||
assert true
|
||||
assert animals.len == 3
|
||||
}
|
||||
|
||||
fn test_is() {
|
||||
dog := Dog{}
|
||||
assert foo2(dog) == 1
|
||||
}
|
||||
|
||||
fn foo2(a Animal) int {
|
||||
if a is Dog {
|
||||
return 1
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user