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

patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script

Problem:    Vim9: comperators use 'ignorecase' in Vim9 script.
Solution:   Ignore 'ignorecase'.  Use true and false instead of 1 and 0.
            (closes #6497)
This commit is contained in:
Bram Moolenaar
2020-07-21 21:31:00 +02:00
parent f868ba8903
commit c71f36a889
5 changed files with 43 additions and 16 deletions

View File

@@ -2413,13 +2413,11 @@ eval3(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
static int static int
eval4(char_u **arg, typval_T *rettv, evalarg_T *evalarg) eval4(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
{ {
typval_T var2;
char_u *p; char_u *p;
int getnext; int getnext;
int i; int i;
exptype_T type = EXPR_UNKNOWN; exptype_T type = EXPR_UNKNOWN;
int len = 2; int len = 2;
int ic;
/* /*
* Get the first variable. * Get the first variable.
@@ -2472,6 +2470,10 @@ eval4(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
*/ */
if (type != EXPR_UNKNOWN) if (type != EXPR_UNKNOWN)
{ {
typval_T var2;
int ic;
int vim9script = in_vim9script();
if (getnext) if (getnext)
*arg = eval_next_line(evalarg); *arg = eval_next_line(evalarg);
@@ -2487,9 +2489,9 @@ eval4(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
ic = FALSE; ic = FALSE;
++len; ++len;
} }
// nothing appended: use 'ignorecase' // nothing appended: use 'ignorecase' if not in Vim script
else else
ic = p_ic; ic = vim9script ? FALSE : p_ic;
/* /*
* Get the second variable. * Get the second variable.
@@ -2504,8 +2506,7 @@ eval4(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
{ {
int ret; int ret;
if (in_vim9script() && check_compare_types( if (vim9script && check_compare_types(type, rettv, &var2) == FAIL)
type, rettv, &var2) == FAIL)
{ {
ret = FAIL; ret = FAIL;
clear_tv(rettv); clear_tv(rettv);

View File

@@ -651,7 +651,7 @@ def Test_expr4_vimscript()
vim9script vim9script
let var = 0 let var = 0
< 1 < 1
assert_equal(1, var) assert_equal(true, var)
END END
CheckScriptSuccess(lines) CheckScriptSuccess(lines)
@@ -659,7 +659,7 @@ def Test_expr4_vimscript()
vim9script vim9script
let var = 123 let var = 123
!= 123 != 123
assert_equal(0, var) assert_equal(false, var)
END END
CheckScriptSuccess(lines) CheckScriptSuccess(lines)
@@ -667,7 +667,7 @@ def Test_expr4_vimscript()
vim9script vim9script
let var = 123 == let var = 123 ==
123 123
assert_equal(1, var) assert_equal(true, var)
END END
CheckScriptSuccess(lines) CheckScriptSuccess(lines)
@@ -676,7 +676,7 @@ def Test_expr4_vimscript()
let list = [1, 2, 3] let list = [1, 2, 3]
let var = list let var = list
is list is list
assert_equal(1, var) assert_equal(true, var)
END END
CheckScriptSuccess(lines) CheckScriptSuccess(lines)
@@ -685,7 +685,7 @@ def Test_expr4_vimscript()
let myblob = 0z1234 let myblob = 0z1234
let var = myblob let var = myblob
isnot 0z11 isnot 0z11
assert_equal(1, var) assert_equal(true, var)
END END
CheckScriptSuccess(lines) CheckScriptSuccess(lines)
@@ -707,6 +707,25 @@ def Test_expr4_vimscript()
echo 123 is 123 echo 123 is 123
END END
CheckScriptFailure(lines, 'Cannot use "is" with number') CheckScriptFailure(lines, 'Cannot use "is" with number')
# check 'ignorecase' not being used
lines =<< trim END
vim9script
set ignorecase
assert_equal(false, 'abc' == 'ABC')
assert_equal(false, 'abc' ==# 'ABC')
assert_equal(true, 'abc' ==? 'ABC')
assert_equal(true, 'abc' != 'ABC')
assert_equal(true, 'abc' !=# 'ABC')
assert_equal(false, 'abc' !=? 'ABC')
assert_equal(false, 'abc' =~ 'ABC')
assert_equal(false, 'abc' =~# 'ABC')
assert_equal(true, 'abc' =~? 'ABC')
set noignorecase
END
CheckScriptSuccess(lines)
enddef enddef
func Test_expr4_fails() func Test_expr4_fails()

View File

@@ -790,8 +790,16 @@ typval_compare(
} }
} }
clear_tv(typ1); clear_tv(typ1);
typ1->v_type = VAR_NUMBER; if (in_vim9script())
typ1->vval.v_number = n1; {
typ1->v_type = VAR_BOOL;
typ1->vval.v_number = n1 ? VVAL_TRUE : VVAL_FALSE;
}
else
{
typ1->v_type = VAR_NUMBER;
typ1->vval.v_number = n1;
}
return OK; return OK;
} }

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 */
/**/
1263,
/**/ /**/
1262, 1262,
/**/ /**/

View File

@@ -2017,9 +2017,6 @@ call_def_function(
typval_compare(tv1, tv2, exptype, ic); typval_compare(tv1, tv2, exptype, ic);
clear_tv(tv2); clear_tv(tv2);
tv1->v_type = VAR_BOOL;
tv1->vval.v_number = tv1->vval.v_number
? VVAL_TRUE : VVAL_FALSE;
--ectx.ec_stack.ga_len; --ectx.ec_stack.ga_len;
} }
break; break;