comparison src/testdir/test_vim9_expr.vim @ 24430:fe71212fd202 v8.2.2755

patch 8.2.2755: Vim9: no error for using a number in a condition Commit: https://github.com/vim/vim/commit/af8ea0d066d31cf3cd0a39c5c49ce0342728588d Author: Bram Moolenaar <Bram@vim.org> Date: Sun Apr 11 18:24:46 2021 +0200 patch 8.2.2755: Vim9: no error for using a number in a condition Problem: Vim9: no error for using a number in a condition. Solution: Also use ISN_COND2BOOL if the type is t_number_bool. (closes #7644)
author Bram Moolenaar <Bram@vim.org>
date Sun, 11 Apr 2021 18:30:05 +0200
parents 492f7b54f691
children aa150abca273
comparison
equal deleted inserted replaced
24429:72b285e88c65 24430:fe71212fd202
280 assert_equal([true], g:vals) 280 assert_equal([true], g:vals)
281 281
282 g:vals = [] 282 g:vals = []
283 assert_equal(false, Record(0) || Record(false) || Record(0)) 283 assert_equal(false, Record(0) || Record(false) || Record(0))
284 assert_equal([0, false, 0], g:vals) 284 assert_equal([0, false, 0], g:vals)
285
286 g:vals = []
287 var x = 1
288 if x || true
289 g:vals = [1]
290 endif
291 assert_equal([1], g:vals)
292
293 g:vals = []
294 x = 3
295 if true || x
296 g:vals = [1]
297 endif
298 assert_equal([1], g:vals)
285 END 299 END
286 CheckDefAndScriptSuccess(lines) 300 CheckDefAndScriptSuccess(lines)
287 enddef 301 enddef
288 302
289 def Test_expr2_vimscript() 303 def Test_expr2_vimscript()
354 368
355 call CheckDefAndScriptFailure2(["if 'yes' || 0", 'echo 0', 'endif'], 'E1012: Type mismatch; expected bool but got string', 'E1135: Using a String as a Bool', 1) 369 call CheckDefAndScriptFailure2(["if 'yes' || 0", 'echo 0', 'endif'], 'E1012: Type mismatch; expected bool but got string', 'E1135: Using a String as a Bool', 1)
356 370
357 # TODO: should fail at compile time 371 # TODO: should fail at compile time
358 call CheckDefExecAndScriptFailure(["var x = 3 || 7"], 'E1023:', 1) 372 call CheckDefExecAndScriptFailure(["var x = 3 || 7"], 'E1023:', 1)
373
374 call CheckDefAndScriptFailure(["if 3"], 'E1023:', 1)
375 call CheckDefExecAndScriptFailure(['var x = 3', 'if x', 'endif'], 'E1023:', 2)
359 376
360 call CheckDefAndScriptFailure2(["var x = [] || false"], 'E1012: Type mismatch; expected bool but got list<unknown>', 'E745:', 1) 377 call CheckDefAndScriptFailure2(["var x = [] || false"], 'E1012: Type mismatch; expected bool but got list<unknown>', 'E745:', 1)
361 378
362 enddef 379 enddef
363 380