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.
diff --git a/src/testdir/test_vim9_disassemble.vim b/src/testdir/test_vim9_disassemble.vim
index 1582f12..78d0a62 100644
--- a/src/testdir/test_vim9_disassemble.vim
+++ b/src/testdir/test_vim9_disassemble.vim
@@ -1199,6 +1199,29 @@
assert_equal(true, InvertBool())
enddef
+def ReturnBool(): bool
+ let var: bool = "no" && [] || 123
+ return var
+enddef
+
+def Test_disassemble_return_bool()
+ let instr = execute('disassemble ReturnBool')
+ assert_match('ReturnBool\_s*' ..
+ 'let var: bool = "no" && \[\] || 123\_s*' ..
+ '0 PUSHS "no"\_s*' ..
+ '1 JUMP_AND_KEEP_IF_FALSE -> 3\_s*' ..
+ '2 NEWLIST size 0\_s*' ..
+ '3 JUMP_AND_KEEP_IF_TRUE -> 5\_s*' ..
+ '4 PUSHNR 123\_s*' ..
+ '5 2BOOL (!!val)\_s*' ..
+ '\d STORE $0\_s*' ..
+ 'return var\_s*' ..
+ '\d LOAD $0\_s*' ..
+ '\d RETURN',
+ instr)
+ assert_equal(true, InvertBool())
+enddef
+
def Test_disassemble_compare()
let cases = [
['true == isFalse', 'COMPAREBOOL =='],
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index 36e39eb..c454ffe 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -46,9 +46,16 @@
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 @@
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:')