comparison src/vim9compile.c @ 33446:508dfc0c261c v9.0.1977

patch 9.0.1977: Vim9: object members can change type Commit: https://github.com/vim/vim/commit/fe7b20a1a39dc645a6ea7ae925512f9227fd1695 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Wed Oct 4 19:47:52 2023 +0200 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>
author Christian Brabandt <cb@256bit.org>
date Wed, 04 Oct 2023 20:00:06 +0200
parents 577ef266309d
children 3de472480e91
comparison
equal deleted inserted replaced
33445:816fd36de6e0 33446:508dfc0c261c
1764 lhs->lhs_name); 1764 lhs->lhs_name);
1765 return FAIL; 1765 return FAIL;
1766 } 1766 }
1767 lhs->lhs_dest = dest_class_member; 1767 lhs->lhs_dest = dest_class_member;
1768 lhs->lhs_class = cctx->ctx_ufunc->uf_class; 1768 lhs->lhs_class = cctx->ctx_ufunc->uf_class;
1769 lhs->lhs_type =
1770 class_member_type_by_idx(cctx->ctx_ufunc->uf_class,
1771 FALSE, lhs->lhs_classmember_idx);
1769 } 1772 }
1770 else 1773 else
1771 { 1774 {
1772 int script_namespace = lhs->lhs_varlen > 1 1775 int script_namespace = lhs->lhs_varlen > 1
1773 && STRNCMP(var_start, "s:", 2) == 0; 1776 && STRNCMP(var_start, "s:", 2) == 0;
3306 semsg(_(e_trailing_characters_str), expr); 3309 semsg(_(e_trailing_characters_str), expr);
3307 goto erret; 3310 goto erret;
3308 } 3311 }
3309 3312
3310 type_T *type = get_type_on_stack(&cctx, 0); 3313 type_T *type = get_type_on_stack(&cctx, 0);
3311 if (m->ocm_type->tt_type != type->tt_type) 3314 if (m->ocm_type->tt_type == VAR_ANY
3315 && !m->ocm_has_type
3316 && type->tt_type != VAR_SPECIAL)
3317 {
3318 // If the member variable type is not yet set, then use
3319 // the initialization expression type.
3320 m->ocm_type = type;
3321 }
3322 else if (m->ocm_type->tt_type != type->tt_type)
3312 { 3323 {
3313 // The type of the member initialization expression is 3324 // The type of the member initialization expression is
3314 // determined at run time. Add a runtime type check. 3325 // determined at run time. Add a runtime type check.
3315 where_T where = WHERE_INIT; 3326 where_T where = WHERE_INIT;
3316 where.wt_kind = WT_MEMBER; 3327 where.wt_kind = WT_MEMBER;