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/vim9expr.c b/src/vim9expr.c
index 8c412b8..7af8bd6 100644
--- a/src/vim9expr.c
+++ b/src/vim9expr.c
@@ -2836,12 +2836,13 @@
type_T *actual;
where_T where = WHERE_INIT;
+ where.wt_kind = WT_CAST;
generate_ppconst(cctx, ppconst);
actual = get_type_on_stack(cctx, 0);
if (check_type_maybe(want_type, actual, FALSE, where) != OK)
{
- if (need_type(actual, want_type, FALSE,
- -1, 0, cctx, FALSE, FALSE) == FAIL)
+ if (need_type_where(actual, want_type, FALSE, -1, where, cctx, FALSE, FALSE)
+ == FAIL)
return FAIL;
}
}