0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

patch 9.1.0988: Vim9: no error when using uninitialized var in new()

Problem:  Vim9: no error when using uninitialized var in new()
          (lifepillar, Aliaksei Budavei)
Solution: Give an error if an uninitialized object variable is referenced
          in new() (Yegappan Lakshmanan)

fixes: #14411
fixes: #16344
closes: #16374

Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Yegappan Lakshmanan
2025-01-03 10:50:08 +01:00
committed by Christian Brabandt
parent 27f2e473e1
commit b04af4cc96
4 changed files with 146 additions and 1 deletions

View File

@@ -4844,6 +4844,20 @@ exec_instructions(ectx_T *ectx)
int arg_set = tv->v_type != VAR_UNKNOWN
&& !(tv->v_type == VAR_SPECIAL
&& tv->vval.v_number == VVAL_NONE);
if (iptr->isn_type == ISN_JUMP_IF_ARG_NOT_SET && !arg_set)
{
dfunc_T *df = ((dfunc_T *)def_functions.ga_data)
+ ectx->ec_dfunc_idx;
ufunc_T *ufunc = df->df_ufunc;
// jump_arg_off is negative for arguments
size_t argidx = ufunc->uf_def_args.ga_len
+ iptr->isn_arg.jumparg.jump_arg_off
+ STACK_FRAME_SIZE;
type_T *t = ufunc->uf_arg_types[argidx];
tv->v_type = t->tt_type;
}
if (iptr->isn_type == ISN_JUMP_IF_ARG_SET ? arg_set : !arg_set)
ectx->ec_iidx = iptr->isn_arg.jumparg.jump_where;
break;
@@ -5718,6 +5732,17 @@ exec_instructions(ectx_T *ectx)
// The members are located right after the object struct.
typval_T *mtv = ((typval_T *)(obj + 1)) + idx;
if (mtv->v_type == VAR_UNKNOWN)
{
// Referencing an object variable (without a type)
// which is not yet initialized. So the type is not
// yet known.
ocmember_T *m = &obj->obj_class->class_obj_members[idx];
SOURCING_LNUM = iptr->isn_lnum;
semsg(_(e_uninitialized_object_var_reference),
m->ocm_name);
goto on_error;
}
copy_tv(mtv, tv);
// Unreference the object after getting the member, it may