1
0
forked from aniani/vim

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>
This commit is contained in:
LemonBoy
2024-07-04 17:03:17 +02:00
committed by Christian Brabandt
parent 05ff4e42fb
commit 50d485432c
7 changed files with 104 additions and 4 deletions

View File

@@ -934,6 +934,7 @@ type_mismatch_where(type_T *expected, type_T *actual, where_T where)
semsg(_(e_argument_nr_type_mismatch_expected_str_but_got_str_in_str),
where.wt_index, typename1, typename2, where.wt_func_name);
break;
case WT_CAST:
case WT_UNKNOWN:
if (where.wt_func_name == NULL)
semsg(_(e_type_mismatch_expected_str_but_got_str),
@@ -1090,7 +1091,15 @@ check_type_maybe(
ret = FAIL;
}
else if (!class_instance_of(actual->tt_class, expected->tt_class))
ret = FAIL;
{
// Check if this is an up-cast, if so we'll have to check the type at
// runtime.
if (where.wt_kind == WT_CAST &&
class_instance_of(expected->tt_class, actual->tt_class))
ret = MAYBE;
else
ret = FAIL;
}
}
if (ret == FAIL && give_msg)