To: vim_dev@googlegroups.com Subject: Patch 9.0.1204 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.1204 Problem: Expression compiled the wrong way after using an object. Solution: Generate constants before getting the type. Files: src/vim9expr.c, src/testdir/test_vim9_class.vim *** ../vim-9.0.1203/src/vim9expr.c 2023-01-11 17:59:35.110319184 +0000 --- src/vim9expr.c 2023-01-15 20:17:25.496341635 +0000 *************** *** 2252,2270 **** if (compile_member(is_slice, &keeping_dict, cctx) == FAIL) return FAIL; } - else if (*p == '.' - && (type = get_type_on_stack(cctx, 0)) != &t_unknown - && (type->tt_type == VAR_CLASS || type->tt_type == VAR_OBJECT)) - { - // class member: SomeClass.varname - // class method: SomeClass.SomeMethod() - // class constructor: SomeClass.new() - // object member: someObject.varname, this.varname - // object method: someObject.SomeMethod(), this.SomeMethod() - *arg = p; - if (compile_class_object_index(cctx, arg, type) == FAIL) - return FAIL; - } else if (*p == '.' && p[1] != '.') { // dictionary member: dict.name --- 2252,2257 ---- *************** *** 2272,2298 **** return FAIL; ppconst->pp_is_const = FALSE; ! *arg = p + 1; ! if (IS_WHITE_OR_NUL(**arg)) { ! emsg(_(e_missing_name_after_dot)); ! return FAIL; } ! p = *arg; ! if (eval_isdictc(*p)) ! while (eval_isnamec(*p)) ! MB_PTR_ADV(p); ! if (p == *arg) { ! semsg(_(e_syntax_error_at_str), *arg); ! return FAIL; } - if (keeping_dict && generate_instr(cctx, ISN_CLEARDICT) == NULL) - return FAIL; - if (generate_STRINGMEMBER(cctx, *arg, p - *arg) == FAIL) - return FAIL; - keeping_dict = TRUE; - *arg = p; } else break; --- 2259,2301 ---- return FAIL; ppconst->pp_is_const = FALSE; ! if ((type = get_type_on_stack(cctx, 0)) != &t_unknown ! && (type->tt_type == VAR_CLASS ! || type->tt_type == VAR_OBJECT)) { ! // class member: SomeClass.varname ! // class method: SomeClass.SomeMethod() ! // class constructor: SomeClass.new() ! // object member: someObject.varname, this.varname ! // object method: someObject.SomeMethod(), this.SomeMethod() ! *arg = p; ! if (compile_class_object_index(cctx, arg, type) == FAIL) ! return FAIL; } ! else { ! *arg = p + 1; ! if (IS_WHITE_OR_NUL(**arg)) ! { ! emsg(_(e_missing_name_after_dot)); ! return FAIL; ! } ! p = *arg; ! if (eval_isdictc(*p)) ! while (eval_isnamec(*p)) ! MB_PTR_ADV(p); ! if (p == *arg) ! { ! semsg(_(e_syntax_error_at_str), *arg); ! return FAIL; ! } ! if (keeping_dict && generate_instr(cctx, ISN_CLEARDICT) == NULL) ! return FAIL; ! if (generate_STRINGMEMBER(cctx, *arg, p - *arg) == FAIL) ! return FAIL; ! keeping_dict = TRUE; ! *arg = p; } } else break; *** ../vim-9.0.1203/src/testdir/test_vim9_class.vim 2023-01-15 16:54:53.746480577 +0000 --- src/testdir/test_vim9_class.vim 2023-01-15 20:16:32.240328476 +0000 *************** *** 240,245 **** --- 240,264 ---- v9.CheckScriptSuccess(lines) enddef + def Test_expr_after_using_object() + var lines =<< trim END + vim9script + + class Something + this.label: string = '' + endclass + + def Foo(): Something + var v = Something.new() + echo 'in Foo(): ' .. typename(v) + return v + enddef + + Foo() + END + v9.CheckScriptSuccess(lines) + enddef + def Test_class_default_new() var lines =<< trim END vim9script *** ../vim-9.0.1203/src/version.c 2023-01-15 18:17:08.789655225 +0000 --- src/version.c 2023-01-15 20:14:47.440302211 +0000 *************** *** 697,698 **** --- 697,700 ---- { /* Add new patch number below this line */ + /**/ + 1204, /**/ -- Shift happens. -- Doppler /// 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 ///