patch 9.1.0523: Vim9: cannot downcast an object
Problem: Vim9: cannot downcast an object (Ernie Rael)
Solution: Fix class downcasting issue (LemonBoy).
When casting an object from one class to another the target type may be
a subclass (downcast) or superclass (upcast) of the source one.
Upcasts require a runtime type check to be emitted.
Add a disassembly test.
fixes: #13244
closes: #15079
Signed-off-by: LemonBoy <thatlemon@gmail.com>
Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 61fefa7..ea305b7 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -522,6 +522,8 @@
(actual->tt_member == &t_void)
== (expected->tt_member == &t_void))))
return TRUE;
+ if (actual->tt_type == VAR_OBJECT && expected->tt_type == VAR_OBJECT)
+ return TRUE;
if ((actual->tt_type == VAR_LIST || actual->tt_type == VAR_DICT)
&& actual->tt_type == expected->tt_type)
// This takes care of a nested list or dict.