summaryrefslogtreecommitdiff
path: root/src/evalvars.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-08-16 21:29:05 +0200
committerBram Moolenaar <Bram@vim.org>2020-08-16 21:29:05 +0200
commit0aae4809fd52b445531766411a9c963dc6274a04 (patch)
treeaf85585a55425e36d08f9e1c7c6f1f8febbef647 /src/evalvars.c
parentf923571ec17b6caeeb7f4abfd7eec3f707ab9c45 (diff)
downloadvim-git-0aae4809fd52b445531766411a9c963dc6274a04.tar.gz
patch 8.2.1469: Vim9: cannot assign string to string optionv8.2.1469
Problem: Vim9: cannot assign string to string option. Solution: Change checks for option value. (closes #6720)
Diffstat (limited to 'src/evalvars.c')
-rw-r--r--src/evalvars.c42
1 files changed, 28 insertions, 14 deletions
diff --git a/src/evalvars.c b/src/evalvars.c
index 0562b4ce2..2f4a11b2c 100644
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -1294,28 +1294,36 @@ ex_let_one(
emsg(_(e_letunexp));
else
{
- long n;
+ long n = 0;
int opt_type;
long numval;
char_u *stringval = NULL;
char_u *s = NULL;
+ int failed = FALSE;
c1 = *p;
*p = NUL;
- n = (long)tv_get_number(tv);
- // avoid setting a string option to the text "v:false" or similar.
- if (tv->v_type != VAR_BOOL && tv->v_type != VAR_SPECIAL)
- s = tv_get_string_chk(tv); // != NULL if number or string
- if (s != NULL && op != NULL && *op != '=')
+ opt_type = get_option_value(arg, &numval, &stringval, opt_flags);
+ if ((opt_type == 1 || opt_type == -1)
+ && (tv->v_type != VAR_STRING || !in_vim9script()))
+ // number, possibly hidden
+ n = (long)tv_get_number(tv);
+
+ // Avoid setting a string option to the text "v:false" or similar.
+ // In Vim9 script also don't convert a number to string.
+ if (tv->v_type != VAR_BOOL && tv->v_type != VAR_SPECIAL
+ && (!in_vim9script() || tv->v_type != VAR_NUMBER))
+ s = tv_get_string_chk(tv);
+
+ if (op != NULL && *op != '=')
{
- opt_type = get_option_value(arg, &numval,
- &stringval, opt_flags);
if ((opt_type == 1 && *op == '.')
|| (opt_type == 0 && *op != '.'))
{
semsg(_(e_letwrong), op);
- s = NULL; // don't set the value
+ failed = TRUE; // don't set the value
+
}
else
{
@@ -1330,19 +1338,25 @@ ex_let_one(
case '%': n = (long)num_modulus(numval, n); break;
}
}
- else if (opt_type == 0 && stringval != NULL) // string
+ else if (opt_type == 0 && stringval != NULL && s != NULL)
{
+ // string
s = concat_str(stringval, s);
vim_free(stringval);
stringval = s;
}
}
}
- if (s != NULL || tv->v_type == VAR_BOOL
- || tv->v_type == VAR_SPECIAL)
+
+ if (!failed)
{
- set_option_value(arg, n, s, opt_flags);
- arg_end = p;
+ if (opt_type != 0 || s != NULL)
+ {
+ set_option_value(arg, n, s, opt_flags);
+ arg_end = p;
+ }
+ else
+ emsg(_(e_stringreq));
}
*p = c1;
vim_free(stringval);