Mercurial > vim
comparison src/typval.c @ 21831:d8422de73113 v8.2.1465
patch 8.2.1465: Vim9: subscript not handled properly
Commit: https://github.com/vim/vim/commit/56acb0943ede35cd9d2f6667cde2442819ccbf59
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Aug 16 14:48:19 2020 +0200
patch 8.2.1465: Vim9: subscript not handled properly
Problem: Vim9: subscript not handled properly.
Solution: Adjust error message. Remove dead code. Disallow string to
number conversion in scripts.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 16 Aug 2020 15:00:05 +0200 |
parents | a6c316ef161a |
children | 727820154b1a |
comparison
equal
deleted
inserted
replaced
21830:bef87368c676 | 21831:d8422de73113 |
---|---|
202 case VAR_FUNC: | 202 case VAR_FUNC: |
203 case VAR_PARTIAL: | 203 case VAR_PARTIAL: |
204 emsg(_("E703: Using a Funcref as a Number")); | 204 emsg(_("E703: Using a Funcref as a Number")); |
205 break; | 205 break; |
206 case VAR_STRING: | 206 case VAR_STRING: |
207 if (in_vim9script()) | |
208 { | |
209 emsg(_(e_using_string_as_number)); | |
210 break; | |
211 } | |
207 if (varp->vval.v_string != NULL) | 212 if (varp->vval.v_string != NULL) |
208 vim_str2nr(varp->vval.v_string, NULL, NULL, | 213 vim_str2nr(varp->vval.v_string, NULL, NULL, |
209 STR2NR_ALL, &n, NULL, 0, FALSE); | 214 STR2NR_ALL, &n, NULL, 0, FALSE); |
210 return n; | 215 return n; |
211 case VAR_LIST: | 216 case VAR_LIST: |
214 case VAR_DICT: | 219 case VAR_DICT: |
215 emsg(_("E728: Using a Dictionary as a Number")); | 220 emsg(_("E728: Using a Dictionary as a Number")); |
216 break; | 221 break; |
217 case VAR_BOOL: | 222 case VAR_BOOL: |
218 case VAR_SPECIAL: | 223 case VAR_SPECIAL: |
224 if (in_vim9script()) | |
225 { | |
226 emsg(_("E611: Using a Special as a Number")); | |
227 break; | |
228 } | |
219 return varp->vval.v_number == VVAL_TRUE ? 1 : 0; | 229 return varp->vval.v_number == VVAL_TRUE ? 1 : 0; |
220 case VAR_JOB: | 230 case VAR_JOB: |
221 #ifdef FEAT_JOB_CHANNEL | 231 #ifdef FEAT_JOB_CHANNEL |
222 emsg(_("E910: Using a Job as a Number")); | 232 emsg(_("E910: Using a Job as a Number")); |
223 break; | 233 break; |
1459 * Returns -1 on error. | 1469 * Returns -1 on error. |
1460 */ | 1470 */ |
1461 linenr_T | 1471 linenr_T |
1462 tv_get_lnum(typval_T *argvars) | 1472 tv_get_lnum(typval_T *argvars) |
1463 { | 1473 { |
1464 linenr_T lnum; | 1474 linenr_T lnum = 0; |
1465 | 1475 |
1466 lnum = (linenr_T)tv_get_number_chk(&argvars[0], NULL); | 1476 if (argvars[0].v_type != VAR_STRING || !in_vim9script()) |
1477 lnum = (linenr_T)tv_get_number_chk(&argvars[0], NULL); | |
1467 if (lnum == 0) // no valid number, try using arg like line() | 1478 if (lnum == 0) // no valid number, try using arg like line() |
1468 { | 1479 { |
1469 int fnum; | 1480 int fnum; |
1470 pos_T *fp = var2fpos(&argvars[0], TRUE, &fnum); | 1481 pos_T *fp = var2fpos(&argvars[0], TRUE, &fnum); |
1471 | 1482 |