1
0
forked from aniani/vim

patch 9.0.1786: Vim9: need instanceof() function

Problem:  Vim9: need instanceof() function
Solution: Implement instanceof() builtin

Implemented in the same form as Python's isinstance because it allows
for checking multiple class types at the same time.

closes: #12867

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: LemonBoy <thatlemon@gmail.com>
This commit is contained in:
LemonBoy
2023-08-23 21:08:11 +02:00
committed by Christian Brabandt
parent 1193951beb
commit afe0466fb1
13 changed files with 212 additions and 19 deletions

View File

@@ -908,20 +908,7 @@ check_type_maybe(
if (actual->tt_type != VAR_OBJECT)
return FAIL; // don't use tt_class
// check the class, base class or an implemented interface matches
class_T *cl;
for (cl = actual->tt_class; cl != NULL; cl = cl->class_extends)
{
if (expected->tt_class == cl)
break;
int i;
for (i = cl->class_interface_count - 1; i >= 0; --i)
if (expected->tt_class == cl->class_interfaces_cl[i])
break;
if (i >= 0)
break;
}
if (cl == NULL)
if (class_instance_of(actual->tt_class, expected->tt_class) == FALSE)
ret = FAIL;
}