Patch 9.0.1483
Problem: += operator does not work on class member.
Solution: Do not skip as if "this." was used. (Christian Brabandt,
closes #12263)
Files: src/vim9compile.c, src/testdir/test_vim9_class.vim
*** ../vim-9.0.1482/src/vim9compile.c 2023-04-22 22:54:28.049802336 +0100
--- src/vim9compile.c 2023-04-24 17:10:01.563226560 +0100
***************
*** 2065,2080 ****
{
if (lhs->lhs_type->tt_type == VAR_OBJECT)
{
! // "this.value": load "this" object and get the value at index
! // for an object or class member get the type of the member
class_T *cl = lhs->lhs_type->tt_class;
! type_T *type = class_member_type(cl, var_start + 5,
lhs->lhs_end, &lhs->lhs_member_idx);
if (lhs->lhs_member_idx < 0)
return FAIL;
! if (generate_LOAD(cctx, ISN_LOAD, 0, NULL, lhs->lhs_type) == FAIL)
! return FAIL;
if (cl->class_flags & CLASS_INTERFACE)
return generate_GET_ITF_MEMBER(cctx, cl, lhs->lhs_member_idx, type);
return generate_GET_OBJ_MEMBER(cctx, lhs->lhs_member_idx, type);
--- 2065,2095 ----
{
if (lhs->lhs_type->tt_type == VAR_OBJECT)
{
! // "this.value": load "this" object and get the value at index for an
! // object or class member get the type of the member.
! // Also for "obj.value".
! char_u *dot = vim_strchr(var_start, '.');
! if (dot == NULL)
! return FAIL;
!
class_T *cl = lhs->lhs_type->tt_class;
! type_T *type = class_member_type(cl, dot + 1,
lhs->lhs_end, &lhs->lhs_member_idx);
if (lhs->lhs_member_idx < 0)
return FAIL;
! if (dot - var_start == 4 && STRNCMP(var_start, "this", 4) == 0)
! {
! // load "this"
! if (generate_LOAD(cctx, ISN_LOAD, 0, NULL, lhs->lhs_type) == FAIL)
! return FAIL;
! }
! else
! {
! // load object variable or argument
! if (compile_load_lhs(lhs, var_start, lhs->lhs_type, cctx) == FAIL)
! return FAIL;
! }
if (cl->class_flags & CLASS_INTERFACE)
return generate_GET_ITF_MEMBER(cctx, cl, lhs->lhs_member_idx, type);
return generate_GET_OBJ_MEMBER(cctx, lhs->lhs_member_idx, type);
***************
*** 2169,2175 ****
if (cctx->ctx_skip == SKIP_YES)
return OK;
! // Load the dict or list. On the stack we then have:
// - value (for assignment, not for :unlet)
// - index
// - for [a : b] second index
--- 2184,2190 ----
if (cctx->ctx_skip == SKIP_YES)
return OK;
! // Load the dict, list or object. On the stack we then have:
// - value (for assignment, not for :unlet)
// - index
// - for [a : b] second index
***************
*** 2731,2737 ****
if (lhs.lhs_has_index)
{
// Use the info in "lhs" to store the value at the index in the
! // list or dict.
if (compile_assign_unlet(var_start, &lhs, TRUE, rhs_type, cctx)
== FAIL)
{
--- 2746,2752 ----
if (lhs.lhs_has_index)
{
// Use the info in "lhs" to store the value at the index in the
! // list, dict or object.
if (compile_assign_unlet(var_start, &lhs, TRUE, rhs_type, cctx)
== FAIL)
{
*** ../vim-9.0.1482/src/testdir/test_vim9_class.vim 2023-04-18 19:07:21.194891892 +0100
--- src/testdir/test_vim9_class.vim 2023-04-24 13:52:50.350343550 +0100
***************
*** 401,406 ****
--- 401,413 ----
var f = Foo.new(3)
f.Add(17)
assert_equal(20, f.x)
+
+ def AddToFoo(obj: Foo)
+ obj.x += 3
+ enddef
+
+ AddToFoo(f)
+ assert_equal(23, f.x)
END
v9.CheckScriptSuccess(lines)
enddef
*** ../vim-9.0.1482/src/version.c 2023-04-23 21:42:01.798657508 +0100
--- src/version.c 2023-04-24 17:14:58.871253987 +0100
***************
*** 697,698 ****
--- 697,700 ----
{ /* Add new patch number below this line */
+ /**/
+ 1483,
/**/
--
To keep milk from turning sour: Keep it in the cow.
/// Bram Moolenaar -- Br...@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 ///