Mercurial > vim
comparison 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 |
comparison
equal
deleted
inserted
replaced
22195:efcf140faa04 | 22196:d835f2fdfcfc |
---|---|
44 assert_equal(v:true, bool1) | 44 assert_equal(v:true, bool1) |
45 let bool2: bool = false | 45 let bool2: bool = false |
46 assert_equal(v:false, bool2) | 46 assert_equal(v:false, bool2) |
47 | 47 |
48 let bool3: bool = 0 | 48 let bool3: bool = 0 |
49 assert_equal(0, bool3) | 49 assert_equal(false, bool3) |
50 let bool4: bool = 1 | 50 let bool4: bool = 1 |
51 assert_equal(1, bool4) | 51 assert_equal(true, bool4) |
52 | |
53 let bool5: bool = 'yes' && 'no' | |
54 assert_equal(true, bool5) | |
55 let bool6: bool = [] && 99 | |
56 assert_equal(false, bool6) | |
57 let bool7: bool = [] || #{a: 1} && 99 | |
58 assert_equal(true, bool7) | |
52 | 59 |
53 let lines =<< trim END | 60 let lines =<< trim END |
54 vim9script | 61 vim9script |
55 def GetFlag(): bool | 62 def GetFlag(): bool |
56 let flag: bool = 1 | 63 let flag: bool = 1 |
57 return flag | 64 return flag |
58 enddef | 65 enddef |
59 let flag: bool = GetFlag() | 66 let flag: bool = GetFlag() |
67 assert_equal(true, flag) | |
60 flag = 0 | 68 flag = 0 |
69 # assert_equal(false, flag) | |
61 flag = 1 | 70 flag = 1 |
71 # assert_equal(true, flag) | |
72 # flag = 99 || 123 | |
73 # assert_equal(true, flag) | |
74 # flag = 'yes' && [] | |
75 # assert_equal(false, flag) | |
62 END | 76 END |
63 CheckScriptSuccess(lines) | 77 CheckScriptSuccess(lines) |
64 CheckDefAndScriptFailure(['let x: bool = 2'], 'E1012:') | 78 CheckDefAndScriptFailure(['let x: bool = 2'], 'E1012:') |
65 CheckDefAndScriptFailure(['let x: bool = -1'], 'E1012:') | 79 CheckDefAndScriptFailure(['let x: bool = -1'], 'E1012:') |
66 CheckDefAndScriptFailure(['let x: bool = [1]'], 'E1012:') | 80 CheckDefAndScriptFailure(['let x: bool = [1]'], 'E1012:') |