0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

patch 8.2.1524: no longer get an error for string concatenation with float

Problem:    No longer get an error for string concatenation with float.
            (Tsuyoshi Cho)
Solution:   Only convert float for Vim9 script. (closes #6787)
This commit is contained in:
Bram Moolenaar
2020-08-25 22:37:48 +02:00
parent b9fc192f92
commit 2e0866128b
3 changed files with 14 additions and 5 deletions

View File

@@ -2675,6 +2675,7 @@ eval5(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
int oplen; int oplen;
int concat; int concat;
typval_T var2; typval_T var2;
int vim9script = in_vim9script();
// "." is only string concatenation when scriptversion is 1 // "." is only string concatenation when scriptversion is 1
p = eval_next_non_blank(*arg, evalarg, &getnext); p = eval_next_non_blank(*arg, evalarg, &getnext);
@@ -2689,7 +2690,7 @@ eval5(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
*arg = eval_next_line(evalarg); *arg = eval_next_line(evalarg);
else else
{ {
if (evaluate && in_vim9script() && !VIM_ISWHITE(**arg)) if (evaluate && vim9script && !VIM_ISWHITE(**arg))
{ {
error_white_both(p, oplen); error_white_both(p, oplen);
clear_tv(rettv); clear_tv(rettv);
@@ -2721,14 +2722,14 @@ eval5(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
/* /*
* Get the second variable. * Get the second variable.
*/ */
if (evaluate && in_vim9script() && !IS_WHITE_OR_NUL((*arg)[oplen])) if (evaluate && vim9script && !IS_WHITE_OR_NUL((*arg)[oplen]))
{ {
error_white_both(p, oplen); error_white_both(p, oplen);
clear_tv(rettv); clear_tv(rettv);
return FAIL; return FAIL;
} }
*arg = skipwhite_and_linebreak(*arg + oplen, evalarg); *arg = skipwhite_and_linebreak(*arg + oplen, evalarg);
if (eval6(arg, &var2, evalarg, !in_vim9script() && op == '.') == FAIL) if (eval6(arg, &var2, evalarg, !vim9script && op == '.') == FAIL)
{ {
clear_tv(rettv); clear_tv(rettv);
return FAIL; return FAIL;
@@ -2745,12 +2746,12 @@ eval5(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
char_u *s1 = tv_get_string_buf(rettv, buf1); char_u *s1 = tv_get_string_buf(rettv, buf1);
char_u *s2 = NULL; char_u *s2 = NULL;
if (in_vim9script() && (var2.v_type == VAR_VOID if (vim9script && (var2.v_type == VAR_VOID
|| var2.v_type == VAR_CHANNEL || var2.v_type == VAR_CHANNEL
|| var2.v_type == VAR_JOB)) || var2.v_type == VAR_JOB))
emsg(_(e_inval_string)); emsg(_(e_inval_string));
#ifdef FEAT_FLOAT #ifdef FEAT_FLOAT
else if (var2.v_type == VAR_FLOAT) else if (vim9script && var2.v_type == VAR_FLOAT)
{ {
vim_snprintf((char *)buf2, NUMBUFLEN, "%g", vim_snprintf((char *)buf2, NUMBUFLEN, "%g",
var2.vval.v_float); var2.vval.v_float);

View File

@@ -135,6 +135,12 @@ func Test_string_concatenation()
let a = 'a' let a = 'a'
let a..=b let a..=b
call assert_equal('ab', a) call assert_equal('ab', a)
if has('float')
let a = 'A'
let b = 1.234
call assert_fails('echo a .. b', 'E806:')
endif
endfunc endfunc
" Test fix for issue #4507 " Test fix for issue #4507

View File

@@ -754,6 +754,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1524,
/**/ /**/
1523, 1523,
/**/ /**/