diff src/testdir/test_vim9_script.vim @ 22196:d835f2fdfcfc v8.2.1647

patch 8.2.1647: Vim9: result of expression with && and || is not a bool Commit: https://github.com/vim/vim/commit/4ed124cc6c0c55385c3b2fed9f9357baf42edbcc Author: Bram Moolenaar <Bram@vim.org> Date: Wed Sep 9 20:03:46 2020 +0200 patch 8.2.1647: Vim9: result of expression with && and || is not a bool Problem: Vim9: result of expression with && and || cannot be assigned to a bool variable. Solution: Add the TTFLAG_BOOL_OK flag and convert the value if needed.
author Bram Moolenaar <Bram@vim.org>
date Wed, 09 Sep 2020 20:15:03 +0200
parents da851f3b6a0b
children 7899b4e2880c
line wrap: on
line diff
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -46,9 +46,16 @@ def Test_assignment_bool()
   assert_equal(v:false, bool2)
 
   let bool3: bool = 0
-  assert_equal(0, bool3)
+  assert_equal(false, bool3)
   let bool4: bool = 1
-  assert_equal(1, bool4)
+  assert_equal(true, bool4)
+
+  let bool5: bool = 'yes' && 'no'
+  assert_equal(true, bool5)
+  let bool6: bool = [] && 99
+  assert_equal(false, bool6)
+  let bool7: bool = [] || #{a: 1} && 99
+  assert_equal(true, bool7)
 
   let lines =<< trim END
     vim9script
@@ -57,8 +64,15 @@ def Test_assignment_bool()
       return flag
     enddef
     let flag: bool = GetFlag()
+    assert_equal(true, flag)
     flag = 0
+    # assert_equal(false, flag)
     flag = 1
+    # assert_equal(true, flag)
+    # flag = 99 || 123
+    # assert_equal(true, flag)
+    # flag = 'yes' && []
+    # assert_equal(false, flag)
   END
   CheckScriptSuccess(lines)
   CheckDefAndScriptFailure(['let x: bool = 2'], 'E1012:')