Patch 8.2.2320
Problem:    Vim9: no error for comparing bool with string.
Solution:   Check for wrong types when comparing. (closes #7639)
Files:      src/typval.c, src/errors.h, src/testdir/test_vim9_expr.vim


*** ../vim-8.2.2319/src/typval.c        2021-01-09 15:45:20.353451132 +0100
--- src/typval.c        2021-01-09 16:11:58.094076957 +0100
***************
*** 834,839 ****
--- 834,863 ----
            default:  break;  // avoid gcc warning
        }
      }
+     else if (in_vim9script() && (typ1->v_type == VAR_BOOL
+                                                || typ2->v_type == VAR_BOOL))
+     {
+       if (typ1->v_type != typ2->v_type)
+       {
+           semsg(_(e_cannot_compare_str_with_str),
+                      vartype_name(typ1->v_type), vartype_name(typ2->v_type));
+           clear_tv(typ1);
+           return FAIL;
+       }
+       n1 = typ1->vval.v_number;
+       n2 = typ2->vval.v_number;
+       switch (type)
+       {
+           case EXPR_IS:
+           case EXPR_EQUAL:    n1 = (n1 == n2); break;
+           case EXPR_ISNOT:
+           case EXPR_NEQUAL:   n1 = (n1 != n2); break;
+           default:
+               emsg(_(e_invalid_operation_for_bool));
+               clear_tv(typ1);
+               return FAIL;
+       }
+     }
      else
      {
        s1 = tv_get_string_buf(typ1, buf1);
*** ../vim-8.2.2319/src/errors.h        2021-01-04 16:15:55.066084896 +0100
--- src/errors.h        2021-01-09 16:09:10.578539104 +0100
***************
*** 341,343 ****
--- 341,345 ----
        INIT(= N_("E1151: Mismatched endfunction"));
  EXTERN char e_mismatched_enddef[]
        INIT(= N_("E1152: Mismatched enddef"));
+ EXTERN char e_invalid_operation_for_bool[]
+       INIT(= N_("E1153: Invalid operation for bool"));
*** ../vim-8.2.2319/src/testdir/test_vim9_expr.vim      2021-01-09 
13:20:32.200472552 +0100
--- src/testdir/test_vim9_expr.vim      2021-01-09 16:16:05.161384252 +0100
***************
*** 597,602 ****
--- 597,614 ----
    CheckDefFailure(["var x = 'a' == "], 'E1097:', 3)
  
    CheckDefExecFailure(['var items: any', 'eval 1', 'eval 2', 'if items == 
[]', 'endif'], 'E691:', 4)
+ 
+   CheckDefExecFailure(['var x: any = "a"', 'echo x == true'], 'E1072: Cannot 
compare string with bool', 2)
+   CheckDefExecFailure(["var x: any = true", 'echo x == ""'], 'E1072: Cannot 
compare bool with string', 2)
+   CheckDefExecFailure(["var x: any = 99", 'echo x == true'], 'E1138', 2)
+   CheckDefExecFailure(["var x: any = 'a'", 'echo x == 99'], 'E1030:', 2)
+ 
+   for op in ['>', '>=', '<', '<=', '=~', '!~']
+     CheckDefExecFailure([
+         "var a: any = 'a'",
+         'var b: any = true',
+         'echo a ' .. op .. ' b'], 'E1072:', 3)
+   endfor
  enddef
  
  " test != comperator
*** ../vim-8.2.2319/src/version.c       2021-01-09 15:45:20.353451132 +0100
--- src/version.c       2021-01-09 16:17:52.645079894 +0100
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     2320,
  /**/

-- 
Support your right to bare arms!  Wear short sleeves!

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202101091522.109FM56l078083%40masaka.moolenaar.net.

Raspunde prin e-mail lui