comparison src/eval.c @ 22391:a9fb7efa31d6 v8.2.1744

patch 8.2.1744: Vim9: using ":const!" is weird Commit: https://github.com/vim/vim/commit/30fd8204cecb317d842b964d624d492088d6d15f Author: Bram Moolenaar <Bram@vim.org> Date: Sat Sep 26 15:09:30 2020 +0200 patch 8.2.1744: Vim9: using ":const!" is weird Problem: Vim9: using ":const!" is weird. Solution: Use "var" - "final" - "const" like Dart. "let" still works for now.
author Bram Moolenaar <Bram@vim.org>
date Sat, 26 Sep 2020 15:15:05 +0200
parents a4866826cebc
children 0e03ef68e738
comparison
equal deleted inserted replaced
22390:ee56fb5ea218 22391:a9fb7efa31d6
1211 set_var_lval( 1211 set_var_lval(
1212 lval_T *lp, 1212 lval_T *lp,
1213 char_u *endp, 1213 char_u *endp,
1214 typval_T *rettv, 1214 typval_T *rettv,
1215 int copy, 1215 int copy,
1216 int flags, // LET_IS_CONST, LET_FORCEIT, LET_NO_COMMAND 1216 int flags, // ASSIGN_CONST, ASSIGN_NO_DECL
1217 char_u *op) 1217 char_u *op)
1218 { 1218 {
1219 int cc; 1219 int cc;
1220 listitem_T *ri; 1220 listitem_T *ri;
1221 dictitem_T *di; 1221 dictitem_T *di;
1279 } 1279 }
1280 else if (op != NULL && *op != '=') 1280 else if (op != NULL && *op != '=')
1281 { 1281 {
1282 typval_T tv; 1282 typval_T tv;
1283 1283
1284 if (flags & LET_IS_CONST) 1284 if (flags & ASSIGN_CONST)
1285 { 1285 {
1286 emsg(_(e_cannot_mod)); 1286 emsg(_(e_cannot_mod));
1287 *endp = cc; 1287 *endp = cc;
1288 return; 1288 return;
1289 } 1289 }
1317 else if (lp->ll_range) 1317 else if (lp->ll_range)
1318 { 1318 {
1319 listitem_T *ll_li = lp->ll_li; 1319 listitem_T *ll_li = lp->ll_li;
1320 int ll_n1 = lp->ll_n1; 1320 int ll_n1 = lp->ll_n1;
1321 1321
1322 if (flags & LET_IS_CONST) 1322 if (flags & ASSIGN_CONST)
1323 { 1323 {
1324 emsg(_("E996: Cannot lock a range")); 1324 emsg(_("E996: Cannot lock a range"));
1325 return; 1325 return;
1326 } 1326 }
1327 1327
1376 else 1376 else
1377 { 1377 {
1378 /* 1378 /*
1379 * Assign to a List or Dictionary item. 1379 * Assign to a List or Dictionary item.
1380 */ 1380 */
1381 if (flags & LET_IS_CONST) 1381 if (flags & ASSIGN_CONST)
1382 { 1382 {
1383 emsg(_("E996: Cannot lock a list or dict")); 1383 emsg(_("E996: Cannot lock a list or dict"));
1384 return; 1384 return;
1385 } 1385 }
1386 if (lp->ll_newkey != NULL) 1386 if (lp->ll_newkey != NULL)
1686 int 1686 int
1687 next_for_item(void *fi_void, char_u *arg) 1687 next_for_item(void *fi_void, char_u *arg)
1688 { 1688 {
1689 forinfo_T *fi = (forinfo_T *)fi_void; 1689 forinfo_T *fi = (forinfo_T *)fi_void;
1690 int result; 1690 int result;
1691 int flag = in_vim9script() ? LET_NO_COMMAND : 0; 1691 int flag = in_vim9script() ? ASSIGN_NO_DECL : 0;
1692 listitem_T *item; 1692 listitem_T *item;
1693 1693
1694 if (fi->fi_blob != NULL) 1694 if (fi->fi_blob != NULL)
1695 { 1695 {
1696 typval_T tv; 1696 typval_T tv;
1739 set_context_for_expression( 1739 set_context_for_expression(
1740 expand_T *xp, 1740 expand_T *xp,
1741 char_u *arg, 1741 char_u *arg,
1742 cmdidx_T cmdidx) 1742 cmdidx_T cmdidx)
1743 { 1743 {
1744 int got_eq = FALSE; 1744 int has_expr = cmdidx != CMD_let && cmdidx != CMD_var;
1745 int c; 1745 int c;
1746 char_u *p; 1746 char_u *p;
1747 1747
1748 if (cmdidx == CMD_let || cmdidx == CMD_const) 1748 if (cmdidx == CMD_let || cmdidx == CMD_var
1749 || cmdidx == CMD_const || cmdidx == CMD_final)
1749 { 1750 {
1750 xp->xp_context = EXPAND_USER_VARS; 1751 xp->xp_context = EXPAND_USER_VARS;
1751 if (vim_strpbrk(arg, (char_u *)"\"'+-*/%.=!?~|&$([<>,#") == NULL) 1752 if (vim_strpbrk(arg, (char_u *)"\"'+-*/%.=!?~|&$([<>,#") == NULL)
1752 { 1753 {
1753 // ":let var1 var2 ...": find last space. 1754 // ":let var1 var2 ...": find last space.
1772 { 1773 {
1773 c = xp->xp_pattern[1]; 1774 c = xp->xp_pattern[1];
1774 if (c == '&') 1775 if (c == '&')
1775 { 1776 {
1776 ++xp->xp_pattern; 1777 ++xp->xp_pattern;
1777 xp->xp_context = cmdidx != CMD_let || got_eq 1778 xp->xp_context = has_expr ? EXPAND_EXPRESSION : EXPAND_NOTHING;
1778 ? EXPAND_EXPRESSION : EXPAND_NOTHING;
1779 } 1779 }
1780 else if (c != ' ') 1780 else if (c != ' ')
1781 { 1781 {
1782 xp->xp_context = EXPAND_SETTINGS; 1782 xp->xp_context = EXPAND_SETTINGS;
1783 if ((c == 'l' || c == 'g') && xp->xp_pattern[2] == ':') 1783 if ((c == 'l' || c == 'g') && xp->xp_pattern[2] == ':')
1790 // environment variable 1790 // environment variable
1791 xp->xp_context = EXPAND_ENV_VARS; 1791 xp->xp_context = EXPAND_ENV_VARS;
1792 } 1792 }
1793 else if (c == '=') 1793 else if (c == '=')
1794 { 1794 {
1795 got_eq = TRUE; 1795 has_expr = TRUE;
1796 xp->xp_context = EXPAND_EXPRESSION; 1796 xp->xp_context = EXPAND_EXPRESSION;
1797 } 1797 }
1798 else if (c == '#' 1798 else if (c == '#'
1799 && xp->xp_context == EXPAND_EXPRESSION) 1799 && xp->xp_context == EXPAND_EXPRESSION)
1800 { 1800 {
1806 && vim_strchr(xp->xp_pattern, '(') == NULL) 1806 && vim_strchr(xp->xp_pattern, '(') == NULL)
1807 { 1807 {
1808 // Function name can start with "<SNR>" and contain '#'. 1808 // Function name can start with "<SNR>" and contain '#'.
1809 break; 1809 break;
1810 } 1810 }
1811 else if (cmdidx != CMD_let || got_eq) 1811 else if (has_expr)
1812 { 1812 {
1813 if (c == '"') // string 1813 if (c == '"') // string
1814 { 1814 {
1815 while ((c = *++xp->xp_pattern) != NUL && c != '"') 1815 while ((c = *++xp->xp_pattern) != NUL && c != '"')
1816 if (c == '\\' && xp->xp_pattern[1] != NUL) 1816 if (c == '\\' && xp->xp_pattern[1] != NUL)