comparison src/eval.c @ 22365:a4866826cebc v8.2.1731

patch 8.2.1731: Vim9: cannot use += to append to empty NULL list Commit: https://github.com/vim/vim/commit/81ed4960482f8baabdd7f95b4d5e39744be88ae7 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Sep 23 15:56:50 2020 +0200 patch 8.2.1731: Vim9: cannot use += to append to empty NULL list Problem: Vim9: cannot use += to append to empty NULL list. Solution: Copy the list instead of extending it. (closes https://github.com/vim/vim/issues/6998)
author Bram Moolenaar <Bram@vim.org>
date Wed, 23 Sep 2020 16:00:04 +0200
parents 07e48ee8c3bb
children a9fb7efa31d6
comparison
equal deleted inserted replaced
22364:436bae5a7f5b 22365:a4866826cebc
870 var1.v_type = VAR_UNKNOWN; 870 var1.v_type = VAR_UNKNOWN;
871 var2.v_type = VAR_UNKNOWN; 871 var2.v_type = VAR_UNKNOWN;
872 while (*p == '[' || (*p == '.' && lp->ll_tv->v_type == VAR_DICT)) 872 while (*p == '[' || (*p == '.' && lp->ll_tv->v_type == VAR_DICT))
873 { 873 {
874 if (!(lp->ll_tv->v_type == VAR_LIST && lp->ll_tv->vval.v_list != NULL) 874 if (!(lp->ll_tv->v_type == VAR_LIST && lp->ll_tv->vval.v_list != NULL)
875 && !(lp->ll_tv->v_type == VAR_DICT 875 && !(lp->ll_tv->v_type == VAR_DICT)
876 && lp->ll_tv->vval.v_dict != NULL)
877 && !(lp->ll_tv->v_type == VAR_BLOB 876 && !(lp->ll_tv->v_type == VAR_BLOB
878 && lp->ll_tv->vval.v_blob != NULL)) 877 && lp->ll_tv->vval.v_blob != NULL))
879 { 878 {
880 if (!quiet) 879 if (!quiet)
881 emsg(_("E689: Can only index a List, Dictionary or Blob")); 880 emsg(_("E689: Can only index a List, Dictionary or Blob"));
992 clear_tv(&var1); 991 clear_tv(&var1);
993 return NULL; 992 return NULL;
994 } 993 }
995 } 994 }
996 lp->ll_list = NULL; 995 lp->ll_list = NULL;
996
997 // a NULL dict is equivalent with an empty dict
998 if (lp->ll_tv->vval.v_dict == NULL)
999 {
1000 lp->ll_tv->vval.v_dict = dict_alloc();
1001 if (lp->ll_tv->vval.v_dict == NULL)
1002 {
1003 clear_tv(&var1);
1004 return NULL;
1005 }
1006 ++lp->ll_tv->vval.v_dict->dv_refcount;
1007 }
997 lp->ll_dict = lp->ll_tv->vval.v_dict; 1008 lp->ll_dict = lp->ll_tv->vval.v_dict;
1009
998 lp->ll_di = dict_find(lp->ll_dict, key, len); 1010 lp->ll_di = dict_find(lp->ll_dict, key, len);
999 1011
1000 // When assigning to a scope dictionary check that a function and 1012 // When assigning to a scope dictionary check that a function and
1001 // variable name is valid (only variable name unless it is l: or 1013 // variable name is valid (only variable name unless it is l: or
1002 // g: dictionary). Disallow overwriting a builtin function. 1014 // g: dictionary). Disallow overwriting a builtin function.
1458 1470
1459 case VAR_LIST: 1471 case VAR_LIST:
1460 if (*op != '+' || tv2->v_type != VAR_LIST) 1472 if (*op != '+' || tv2->v_type != VAR_LIST)
1461 break; 1473 break;
1462 // List += List 1474 // List += List
1463 if (tv1->vval.v_list != NULL && tv2->vval.v_list != NULL) 1475 if (tv2->vval.v_list != NULL)
1464 list_extend(tv1->vval.v_list, tv2->vval.v_list, NULL); 1476 {
1477 if (tv1->vval.v_list == NULL)
1478 {
1479 tv1->vval.v_list = tv2->vval.v_list;
1480 ++tv1->vval.v_list->lv_refcount;
1481 }
1482 else
1483 list_extend(tv1->vval.v_list, tv2->vval.v_list, NULL);
1484 }
1465 return OK; 1485 return OK;
1466 1486
1467 case VAR_NUMBER: 1487 case VAR_NUMBER:
1468 case VAR_STRING: 1488 case VAR_STRING:
1469 if (tv2->v_type == VAR_LIST) 1489 if (tv2->v_type == VAR_LIST)