To: vim_dev@googlegroups.com Subject: Patch 9.0.1147 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.1147 Problem: Cannot access a class member in a compiled function. Solution: Implement looking up a class member. Files: src/vim9expr.c, src/testdir/test_vim9_class.vim *** ../vim-9.0.1146/src/vim9expr.c 2023-01-03 19:08:46.001020599 +0000 --- src/vim9expr.c 2023-01-04 18:43:52.691996468 +0000 *************** *** 263,268 **** --- 263,284 ---- return FAIL; } + if (type->tt_type == VAR_CLASS) + { + garray_T *instr = &cctx->ctx_instr; + if (instr->ga_len > 0) + { + isn_T *isn = ((isn_T *)instr->ga_data) + instr->ga_len - 1; + if (isn->isn_type == ISN_LOADSCRIPT) + { + // The class was recognized as a script item. We only need + // to know what class it is, drop the instruction. + --instr->ga_len; + vim_free(isn->isn_arg.script.scriptref); + } + } + } + ++*arg; char_u *name = *arg; char_u *name_end = find_name_end(name, NULL, NULL, FNE_CHECK_START); *************** *** 278,296 **** if (type->tt_type == VAR_CLASS) { - garray_T *instr = &cctx->ctx_instr; - if (instr->ga_len > 0) - { - isn_T *isn = ((isn_T *)instr->ga_data) + instr->ga_len - 1; - if (isn->isn_type == ISN_LOADSCRIPT) - { - // The class was recognized as a script item. We only need - // to know what class it is, drop the instruction. - --instr->ga_len; - vim_free(isn->isn_arg.script.scriptref); - } - } - function_count = cl->class_class_function_count; functions = cl->class_class_functions; } --- 294,299 ---- *************** *** 344,353 **** return FAIL; } - generate_GET_OBJ_MEMBER(cctx, i, m->ocm_type); - *arg = name_end; ! return OK; } } --- 347,354 ---- return FAIL; } *arg = name_end; ! return generate_GET_OBJ_MEMBER(cctx, i, m->ocm_type); } } *************** *** 355,362 **** } else { ! // TODO: class member ! emsg("compile_class_object_index(): class member not handled yet"); } return FAIL; --- 356,375 ---- } else { ! // load class member ! int idx; ! for (idx = 0; idx < cl->class_class_member_count; ++idx) ! { ! ocmember_T *m = &cl->class_class_members[idx]; ! if (STRNCMP(name, m->ocm_name, len) == 0 && m->ocm_name[len] == NUL) ! break; ! } ! if (idx < cl->class_class_member_count) ! { ! *arg = name_end; ! return generate_CLASSMEMBER(cctx, TRUE, cl, idx); ! } ! semsg(_(e_class_member_not_found_str), name); } return FAIL; *** ../vim-9.0.1146/src/testdir/test_vim9_class.vim 2023-01-03 19:08:46.005020599 +0000 --- src/testdir/test_vim9_class.vim 2023-01-04 18:48:56.307624889 +0000 *************** *** 439,444 **** --- 439,449 ---- TextPos.AddToCounter(3) assert_equal(3, TextPos.counter) assert_fails('echo TextPos.noSuchMember', 'E1338:') + + def GetCounter(): number + return TextPos.counter + enddef + assert_equal(3, GetCounter()) assert_fails('TextPos.noSuchMember = 2', 'E1337:') assert_fails('TextPos.counter = 5', 'E1335:') *** ../vim-9.0.1146/src/version.c 2023-01-04 18:05:55.408803650 +0000 --- src/version.c 2023-01-04 18:53:38.252003818 +0000 *************** *** 697,698 **** --- 697,700 ---- { /* Add new patch number below this line */ + /**/ + 1147, /**/ -- ARTHUR: The swallow may fly south with the sun, or the house martin or the plover seek warmer hot lands in winter, yet these are not strangers to our land. SOLDIER: Are you suggesting coconuts migrate? "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// 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 ///