From c71f36a889897aca4ac2ad3828926e3801728336 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Tue, 21 Jul 2020 21:31:00 +0200 Subject: [PATCH] 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) --- src/eval.c | 13 +++++++------ src/testdir/test_vim9_expr.vim | 29 ++++++++++++++++++++++++----- src/typval.c | 12 ++++++++++-- src/version.c | 2 ++ src/vim9execute.c | 3 --- 5 files changed, 43 insertions(+), 16 deletions(-) diff --git a/src/eval.c b/src/eval.c index 307a2aec7..c3f0ee5c9 100644 --- a/src/eval.c +++ b/src/eval.c @@ -2413,13 +2413,11 @@ eval3(char_u **arg, typval_T *rettv, evalarg_T *evalarg) static int eval4(char_u **arg, typval_T *rettv, evalarg_T *evalarg) { - typval_T var2; char_u *p; int getnext; int i; exptype_T type = EXPR_UNKNOWN; int len = 2; - int ic; /* * Get the first variable. @@ -2472,6 +2470,10 @@ eval4(char_u **arg, typval_T *rettv, evalarg_T *evalarg) */ if (type != EXPR_UNKNOWN) { + typval_T var2; + int ic; + int vim9script = in_vim9script(); + if (getnext) *arg = eval_next_line(evalarg); @@ -2487,9 +2489,9 @@ eval4(char_u **arg, typval_T *rettv, evalarg_T *evalarg) ic = FALSE; ++len; } - // nothing appended: use 'ignorecase' + // nothing appended: use 'ignorecase' if not in Vim script else - ic = p_ic; + ic = vim9script ? FALSE : p_ic; /* * Get the second variable. @@ -2504,8 +2506,7 @@ eval4(char_u **arg, typval_T *rettv, evalarg_T *evalarg) { int ret; - if (in_vim9script() && check_compare_types( - type, rettv, &var2) == FAIL) + if (vim9script && check_compare_types(type, rettv, &var2) == FAIL) { ret = FAIL; clear_tv(rettv); diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim index 4c9db5cf6..d6cbd037d 100644 --- a/src/testdir/test_vim9_expr.vim +++ b/src/testdir/test_vim9_expr.vim @@ -651,7 +651,7 @@ def Test_expr4_vimscript() vim9script let var = 0 < 1 - assert_equal(1, var) + assert_equal(true, var) END CheckScriptSuccess(lines) @@ -659,7 +659,7 @@ def Test_expr4_vimscript() vim9script let var = 123 != 123 - assert_equal(0, var) + assert_equal(false, var) END CheckScriptSuccess(lines) @@ -667,7 +667,7 @@ def Test_expr4_vimscript() vim9script let var = 123 == 123 - assert_equal(1, var) + assert_equal(true, var) END CheckScriptSuccess(lines) @@ -676,7 +676,7 @@ def Test_expr4_vimscript() let list = [1, 2, 3] let var = list is list - assert_equal(1, var) + assert_equal(true, var) END CheckScriptSuccess(lines) @@ -685,7 +685,7 @@ def Test_expr4_vimscript() let myblob = 0z1234 let var = myblob isnot 0z11 - assert_equal(1, var) + assert_equal(true, var) END CheckScriptSuccess(lines) @@ -707,6 +707,25 @@ def Test_expr4_vimscript() echo 123 is 123 END 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 func Test_expr4_fails() diff --git a/src/typval.c b/src/typval.c index 9d0c6acd4..e87f91096 100644 --- a/src/typval.c +++ b/src/typval.c @@ -790,8 +790,16 @@ typval_compare( } } clear_tv(typ1); - typ1->v_type = VAR_NUMBER; - typ1->vval.v_number = n1; + if (in_vim9script()) + { + 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; } diff --git a/src/version.c b/src/version.c index f34bb8dbc..a26908213 100644 --- a/src/version.c +++ b/src/version.c @@ -754,6 +754,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1263, /**/ 1262, /**/ diff --git a/src/vim9execute.c b/src/vim9execute.c index d83ac5a30..c75e09554 100644 --- a/src/vim9execute.c +++ b/src/vim9execute.c @@ -2017,9 +2017,6 @@ call_def_function( typval_compare(tv1, tv2, exptype, ic); 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; } break; -- 2.40.0