mirror of
https://github.com/vim/vim.git
synced 2025-09-23 03:43:49 -04:00
patch 9.0.1977: Vim9: object members can change type
Problem: Vim9: object members can change type Solution: Check type during assignment to object/class var closes: #13127 closes: #13262 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
committed by
Christian Brabandt
parent
b9a974df9e
commit
fe7b20a1a3
@@ -1766,6 +1766,9 @@ compile_lhs(
|
||||
}
|
||||
lhs->lhs_dest = dest_class_member;
|
||||
lhs->lhs_class = cctx->ctx_ufunc->uf_class;
|
||||
lhs->lhs_type =
|
||||
class_member_type_by_idx(cctx->ctx_ufunc->uf_class,
|
||||
FALSE, lhs->lhs_classmember_idx);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -3308,7 +3311,15 @@ compile_def_function(
|
||||
}
|
||||
|
||||
type_T *type = get_type_on_stack(&cctx, 0);
|
||||
if (m->ocm_type->tt_type != type->tt_type)
|
||||
if (m->ocm_type->tt_type == VAR_ANY
|
||||
&& !m->ocm_has_type
|
||||
&& type->tt_type != VAR_SPECIAL)
|
||||
{
|
||||
// If the member variable type is not yet set, then use
|
||||
// the initialization expression type.
|
||||
m->ocm_type = type;
|
||||
}
|
||||
else if (m->ocm_type->tt_type != type->tt_type)
|
||||
{
|
||||
// The type of the member initialization expression is
|
||||
// determined at run time. Add a runtime type check.
|
||||
|
Reference in New Issue
Block a user