comparison src/testdir/test_vim9_expr.vim @ 22860:53acb89ec9f2 v8.2.1977

patch 8.2.1977: Vim9: error for using a string in a condition is confusing Commit: https://github.com/vim/vim/commit/ea2d407f9c144bb634c59017944e4930ed7f80a2 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Nov 12 12:08:51 2020 +0100 patch 8.2.1977: Vim9: error for using a string in a condition is confusing Problem: Vim9: error for using a string in a condition is confusing. Solution: Give a more specific error. Also adjust the compile time type checking for || and &&.
author Bram Moolenaar <Bram@vim.org>
date Thu, 12 Nov 2020 12:15:04 +0100
parents b129f28b0e35
children 52e64d340a98
comparison
equal deleted inserted replaced
22859:757858b35433 22860:53acb89ec9f2
129 129
130 lines =<< trim END 130 lines =<< trim END
131 vim9script 131 vim9script
132 var name = 'x' ? 1 : 2 132 var name = 'x' ? 1 : 2
133 END 133 END
134 CheckScriptFailure(lines, 'E1030:', 2) 134 CheckScriptFailure(lines, 'E1135:', 2)
135 135
136 lines =<< trim END 136 lines =<< trim END
137 vim9script 137 vim9script
138 var name = [] ? 1 : 2 138 var name = [] ? 1 : 2
139 END 139 END
178 let msg = "White space required before and after ':'" 178 let msg = "White space required before and after ':'"
179 call CheckDefFailure(["var x = 1 ? 'one': 'two'"], msg, 1) 179 call CheckDefFailure(["var x = 1 ? 'one': 'two'"], msg, 1)
180 call CheckDefFailure(["var x = 1 ? 'one' :'two'"], msg, 1) 180 call CheckDefFailure(["var x = 1 ? 'one' :'two'"], msg, 1)
181 call CheckDefFailure(["var x = 1 ? 'one':'two'"], msg, 1) 181 call CheckDefFailure(["var x = 1 ? 'one':'two'"], msg, 1)
182 182
183 call CheckDefFailure(["var x = 'x' ? 'one' : 'two'"], 'E1030:', 1) 183 call CheckDefFailure(["var x = 'x' ? 'one' : 'two'"], 'E1135:', 1)
184 call CheckDefFailure(["var x = 0z1234 ? 'one' : 'two'"], 'E974:', 1) 184 call CheckDefFailure(["var x = 0z1234 ? 'one' : 'two'"], 'E974:', 1)
185 call CheckDefExecFailure(["var x = [] ? 'one' : 'two'"], 'E745:', 1) 185 call CheckDefExecFailure(["var x = [] ? 'one' : 'two'"], 'E745:', 1)
186 call CheckDefExecFailure(["var x = {} ? 'one' : 'two'"], 'E728:', 1) 186 call CheckDefExecFailure(["var x = {} ? 'one' : 'two'"], 'E728:', 1)
187 187
188 if has('float') 188 if has('float')
354 call CheckDefFailure(["var x = 1||2"], msg, 1) 354 call CheckDefFailure(["var x = 1||2"], msg, 1)
355 call CheckDefFailure(["var x = 1 ||2"], msg, 1) 355 call CheckDefFailure(["var x = 1 ||2"], msg, 1)
356 call CheckDefFailure(["var x = 1|| 2"], msg, 1) 356 call CheckDefFailure(["var x = 1|| 2"], msg, 1)
357 357
358 call CheckDefFailure(["var x = 1 || xxx"], 'E1001:', 1) 358 call CheckDefFailure(["var x = 1 || xxx"], 'E1001:', 1)
359 call CheckDefFailure(["var x = [] || false"], 'E1012:', 1)
360 call CheckDefFailure(["if 'yes' || 0", 'echo 0', 'endif'], 'E1012: Type mismatch; expected bool but got string', 1)
359 361
360 # TODO: should fail at compile time 362 # TODO: should fail at compile time
361 call CheckDefExecFailure(["var x = 3 || 7"], 'E1023:', 1) 363 call CheckDefExecFailure(["var x = 3 || 7"], 'E1023:', 1)
362 call CheckScriptFailure(["vim9script", "var x = 3 || 7"], 'E1023:', 2) 364 call CheckScriptFailure(["vim9script", "var x = 3 || 7"], 'E1023:', 2)
363 call CheckDefExecFailure(["var x = [] || false"], 'E745:', 1)
364 call CheckScriptFailure(["vim9script", "var x = [] || false"], 'E745:', 2) 365 call CheckScriptFailure(["vim9script", "var x = [] || false"], 'E745:', 2)
365 enddef 366 enddef
366 367
367 " test && 368 " test &&
368 def Test_expr3() 369 def Test_expr3()
490 func Test_expr3_fails() 491 func Test_expr3_fails()
491 let msg = "White space required before and after '&&'" 492 let msg = "White space required before and after '&&'"
492 call CheckDefFailure(["var x = 1&&2"], msg, 1) 493 call CheckDefFailure(["var x = 1&&2"], msg, 1)
493 call CheckDefFailure(["var x = 1 &&2"], msg, 1) 494 call CheckDefFailure(["var x = 1 &&2"], msg, 1)
494 call CheckDefFailure(["var x = 1&& 2"], msg, 1) 495 call CheckDefFailure(["var x = 1&& 2"], msg, 1)
496
497 call CheckDefFailure(["if 'yes' && 0", 'echo 0', 'endif'], 'E1012: Type mismatch; expected bool but got string', 1)
495 endfunc 498 endfunc
496 499
497 " global variables to use for tests with the "any" type 500 " global variables to use for tests with the "any" type
498 let atrue = v:true 501 let atrue = v:true
499 let afalse = v:false 502 let afalse = v:false