Mercurial > vim
comparison src/testdir/test_vim9_assign.vim @ 33466:3de472480e91 v9.0.1986
patch 9.0.1986: Vim9: accepting type-annotations
Commit: https://github.com/vim/vim/commit/b5a0719cb7abf51b0540df527cb9738a3ccf0d37
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Thu Oct 5 20:14:43 2023 +0200
patch 9.0.1986: Vim9: accepting type-annotations
Problem: Vim9: accepting type-annotations
Solution: Reject type annotations outside of declarations.
closes: #13267
closes: #13283
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 05 Oct 2023 20:30:08 +0200 |
parents | 695b50472e85 |
children | 9dee279ce1c4 |
comparison
equal
deleted
inserted
replaced
33465:16445e83c2fd | 33466:3de472480e91 |
---|---|
2820 call assert_equal(456, s:scriptlevel) | 2820 call assert_equal(456, s:scriptlevel) |
2821 END | 2821 END |
2822 v9.CheckScriptSuccess(lines) | 2822 v9.CheckScriptSuccess(lines) |
2823 enddef | 2823 enddef |
2824 | 2824 |
2825 " Test for specifying a type in assignment | |
2826 def Test_type_specification_in_assignment() | |
2827 # specify type for an existing script local variable without "var" | |
2828 var lines =<< trim END | |
2829 vim9script | |
2830 var n: number = 10 | |
2831 n: number = 20 | |
2832 END | |
2833 v9.CheckSourceFailure(lines, 'E488: Trailing characters: : number = 20', 3) | |
2834 | |
2835 # specify type for a non-existing script local variable without "var" | |
2836 lines =<< trim END | |
2837 vim9script | |
2838 MyVar: string = 'abc' | |
2839 END | |
2840 v9.CheckSourceFailure(lines, "E492: Not an editor command: MyVar: string = 'abc'", 2) | |
2841 | |
2842 # specify type for an existing def local variable without "var" | |
2843 lines =<< trim END | |
2844 vim9script | |
2845 def Foo() | |
2846 var n: number = 10 | |
2847 n: number = 20 | |
2848 enddef | |
2849 Foo() | |
2850 END | |
2851 v9.CheckSourceFailure(lines, 'E488: Trailing characters: : number = 20', 2) | |
2852 | |
2853 # specify type for a non-existing def local variable without "var" | |
2854 lines =<< trim END | |
2855 vim9script | |
2856 def Foo() | |
2857 MyVar: string = 'abc' | |
2858 enddef | |
2859 Foo() | |
2860 END | |
2861 v9.CheckSourceFailure(lines, "E476: Invalid command: MyVar: string = 'abc'", 1) | |
2862 enddef | |
2863 | |
2825 let g:someVar = 'X' | 2864 let g:someVar = 'X' |
2826 | 2865 |
2827 " Test for heredoc with Vim expressions. | 2866 " Test for heredoc with Vim expressions. |
2828 " This messes up highlighting, keep it near the end. | 2867 " This messes up highlighting, keep it near the end. |
2829 def Test_heredoc_expr() | 2868 def Test_heredoc_expr() |