To: vim_dev@googlegroups.com Subject: Patch 9.0.1317 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.1317 Problem: Crash when using an unset object variable. Solution: Give an error instead. (closes #12005) Files: src/vim9class.c, src/errors.h, src/testdir/test_vim9_class.vim *** ../vim-9.0.1316/src/vim9class.c 2023-01-28 15:19:36.960757169 +0000 --- src/vim9class.c 2023-02-17 21:08:30.541722521 +0000 *************** *** 1234,1242 **** evalarg_T *evalarg, int verbose UNUSED) // give error messages { - // int evaluate = evalarg != NULL - // && (evalarg->eval_flags & EVAL_EVALUATE); - if (VIM_ISWHITE((*arg)[1])) { semsg(_(e_no_white_space_allowed_after_str_str), ".", *arg); --- 1234,1239 ---- *************** *** 1250,1257 **** return FAIL; size_t len = name_end - name; ! class_T *cl = rettv->v_type == VAR_CLASS ? rettv->vval.v_class ! : rettv->vval.v_object->obj_class; if (*name_end == '(') { int on_class = rettv->v_type == VAR_CLASS; --- 1247,1265 ---- return FAIL; size_t len = name_end - name; ! class_T *cl; ! if (rettv->v_type == VAR_CLASS) ! cl = rettv->vval.v_class; ! else // VAR_OBJECT ! { ! if (rettv->vval.v_object == NULL) ! { ! emsg(_(e_using_null_object)); ! return FAIL; ! } ! cl = rettv->vval.v_object->obj_class; ! } ! if (*name_end == '(') { int on_class = rettv->v_type == VAR_CLASS; *** ../vim-9.0.1316/src/errors.h 2023-01-27 13:16:14.674850404 +0000 --- src/errors.h 2023-02-17 20:59:32.385320074 +0000 *************** *** 1182,1187 **** --- 1182,1189 ---- INIT(= N_("E476: Invalid command")); EXTERN char e_invalid_command_str[] INIT(= N_("E476: Invalid command: %s")); + EXTERN char e_invalid_command_str_expected_str[] + INIT(= N_("E476: Invalid command: %s, expected %s")); EXTERN char e_no_bang_allowed[] INIT(= N_("E477: No ! allowed")); EXTERN char e_dont_panic[] *************** *** 3442,3447 **** INIT(= N_("E1358: Using \"super\" not in a child class")); EXTERN char e_cannot_define_new_function_in_abstract_class[] INIT(= N_("E1359: Cannot define a \"new\" function in an abstract class")); ! EXTERN char e_invalid_command_str_expected_str[] ! INIT(= N_("E476: Invalid command: %s, expected %s")); #endif --- 3444,3449 ---- INIT(= N_("E1358: Using \"super\" not in a child class")); EXTERN char e_cannot_define_new_function_in_abstract_class[] INIT(= N_("E1359: Cannot define a \"new\" function in an abstract class")); ! EXTERN char e_using_null_object[] ! INIT(= N_("E1360: Using a null object")); #endif *** ../vim-9.0.1316/src/testdir/test_vim9_class.vim 2023-02-10 15:52:21.654002123 +0000 --- src/testdir/test_vim9_class.vim 2023-02-17 21:04:44.697584401 +0000 *************** *** 182,187 **** --- 182,202 ---- v9.CheckScriptFailure(lines, 'E476: Invalid command: endclass, expected endinterface') enddef + def Test_object_not_set() + var lines =<< trim END + vim9script + + class State + this.value = 'xyz' + endclass + + var state: State + var db = {'xyz': 789} + echo db[state.value] + END + v9.CheckScriptFailure(lines, 'E1360:') + enddef + def Test_class_member_initializer() var lines =<< trim END vim9script *** ../vim-9.0.1316/src/version.c 2023-02-17 20:04:47.428687255 +0000 --- src/version.c 2023-02-17 21:00:31.665379085 +0000 *************** *** 697,698 **** --- 697,700 ---- { /* Add new patch number below this line */ + /**/ + 1317, /**/ -- Birthdays are healthy. The more you have them, the longer you live. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///