comparison src/testdir/test_vim9_func.vim @ 26925:4e77f9961650 v8.2.3991

patch 8.2.3991: Vim9: error when extending dict<any> Commit: https://github.com/vim/vim/commit/114dbda7858df956161c0adba5d4d8279645ff67 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Jan 3 12:28:03 2022 +0000 patch 8.2.3991: Vim9: error when extending dict<any> Problem: Vim9: error when extending dict<any> with another type that it was initialized with. Solution: Also set the type for dict<any> if the initializer has a more specific type. (closes #9461)
author Bram Moolenaar <Bram@vim.org>
date Mon, 03 Jan 2022 13:30:04 +0100
parents 15913ba6363e
children 043a15b37bf1
comparison
equal deleted inserted replaced
26924:9a1e933647aa 26925:4e77f9961650
437 CheckScriptFailure(lines, 'E1010:') 437 CheckScriptFailure(lines, 'E1010:')
438 CheckScriptFailure(lines, 'E1010:') 438 CheckScriptFailure(lines, 'E1010:')
439 enddef 439 enddef
440 440
441 def Test_return_list_any() 441 def Test_return_list_any()
442 # This used to fail but now the actual list type is checked, and since it has
443 # an item of type string it can be used as list<string>.
442 var lines =<< trim END 444 var lines =<< trim END
443 vim9script 445 vim9script
444 def Func(): list<string> 446 def Func(): list<string>
445 var l: list<any> 447 var l: list<any>
446 l->add('string') 448 l->add('string')
447 return l 449 return l
448 enddef 450 enddef
449 echo Func() 451 echo Func()
450 END 452 END
451 CheckScriptFailure(lines, 'E1012:') 453 CheckScriptSuccess(lines)
454
452 lines =<< trim END 455 lines =<< trim END
453 vim9script 456 vim9script
454 def Func(): list<string> 457 def Func(): list<string>
455 var l: list<any> 458 var l: list<any>
456 l += ['string'] 459 l += ['string']
457 return l 460 return l
458 enddef 461 enddef
459 echo Func() 462 echo Func()
460 END 463 END
461 CheckScriptFailure(lines, 'E1012:') 464 CheckScriptSuccess(lines)
462 enddef 465 enddef
463 466
464 func Increment() 467 func Increment()
465 let g:counter += 1 468 let g:counter += 1
466 endfunc 469 endfunc