Mercurial > vim
comparison src/testdir/test_vim9_func.vim @ 20255:aac52c32a91f v8.2.0683
patch 8.2.0683: Vim9: parsing type does not always work
Commit: https://github.com/vim/vim/commit/5adc55cb746893c6ddf7865ff654582902dee2e3
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat May 2 23:12:58 2020 +0200
patch 8.2.0683: Vim9: parsing type does not always work
Problem: Vim9: parsing type does not always work.
Solution: Handle func type without return value. Test more closures.
Fix type check offset. Fix garbage collection.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 02 May 2020 23:15:03 +0200 |
parents | 6f9010b6f7f9 |
children | 683c2da4982b |
comparison
equal
deleted
inserted
replaced
20254:c7a2968adc24 | 20255:aac52c32a91f |
---|---|
660 MakeRef() | 660 MakeRef() |
661 assert_equal('some thing', g:Ref('thing')) | 661 assert_equal('some thing', g:Ref('thing')) |
662 unlet g:Ref | 662 unlet g:Ref |
663 enddef | 663 enddef |
664 | 664 |
665 def MakeTwoRefs() | |
666 let local = ['some'] | |
667 g:Extend = {s -> local->add(s)} | |
668 g:Read = {-> local} | |
669 enddef | |
670 | |
671 def Test_closure_two_refs() | |
672 MakeTwoRefs() | |
673 assert_equal('some', join(g:Read(), ' ')) | |
674 g:Extend('more') | |
675 assert_equal('some more', join(g:Read(), ' ')) | |
676 g:Extend('even') | |
677 assert_equal('some more even', join(g:Read(), ' ')) | |
678 | |
679 unlet g:Extend | |
680 unlet g:Read | |
681 enddef | |
682 | |
683 " TODO: fix memory leak when using same function again. | |
684 def MakeTwoRefs_2() | |
685 let local = ['some'] | |
686 g:Extend = {s -> local->add(s)} | |
687 g:Read = {-> local} | |
688 enddef | |
689 | |
690 def ReadRef(Ref: func(): list<string>): string | |
691 return join(Ref(), ' ') | |
692 enddef | |
693 | |
694 def ExtendRef(Ref: func(string), add: string) | |
695 Ref(add) | |
696 enddef | |
697 | |
698 def Test_closure_two_indirect_refs() | |
699 MakeTwoRefs_2() | |
700 assert_equal('some', ReadRef(g:Read)) | |
701 ExtendRef(g:Extend, 'more') | |
702 assert_equal('some more', ReadRef(g:Read)) | |
703 ExtendRef(g:Extend, 'even') | |
704 assert_equal('some more even', ReadRef(g:Read)) | |
705 | |
706 unlet g:Extend | |
707 unlet g:Read | |
708 enddef | |
665 | 709 |
666 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker | 710 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker |