comparison src/testdir/test_vim9_script.vim @ 33961:07ac92709982 v9.0.2173

patch 9.0.2173: Vim9: crash when compiling for statement and non-existing type Commit: https://github.com/vim/vim/commit/062bb6b9099f4c92e10465e5ff98db092a3eac1b Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Sat Dec 16 14:46:40 2023 +0100 patch 9.0.2173: Vim9: crash when compiling for statement and non-existing type Problem: Vim9: Vim crashes when compiling a for statement with a non-existing type Solution: Error out when lhs_type is not null closes: #13703 Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Sat, 16 Dec 2023 15:00:04 +0100
parents 07d5c4814c45
children c4ad4778946c
comparison
equal deleted inserted replaced
33960:c61602501ba9 33961:07ac92709982
2696 endfor 2696 endfor
2697 END 2697 END
2698 v9.CheckDefSuccess(lines) 2698 v9.CheckDefSuccess(lines)
2699 2699
2700 v9.CheckDefFailure(['for x in range(3)'] + lines + ['endfor'], 'E1306:') 2700 v9.CheckDefFailure(['for x in range(3)'] + lines + ['endfor'], 'E1306:')
2701
2702 # Test for too many for loops
2703 lines =<< trim END
2704 vim9script
2705 def Foo()
2706 for a in range(1)
2707 for b in range(1)
2708 for c in range(1)
2709 for d in range(1)
2710 for e in range(1)
2711 for f in range(1)
2712 for g in range(1)
2713 for h in range(1)
2714 for i in range(1)
2715 for j in range(1)
2716 for k in range(1)
2717 endfor
2718 endfor
2719 endfor
2720 endfor
2721 endfor
2722 endfor
2723 endfor
2724 endfor
2725 endfor
2726 endfor
2727 endfor
2728 enddef
2729 defcompile
2730 END
2731 v9.CheckSourceFailure(lines, 'E1306: Loop nesting too deep', 11)
2701 enddef 2732 enddef
2702 2733
2703 def Test_for_loop_script_var() 2734 def Test_for_loop_script_var()
2704 # cannot use s:var in a :def function 2735 # cannot use s:var in a :def function
2705 v9.CheckDefFailure(['for s:var in range(3)', 'echo 3'], 'E1254:') 2736 v9.CheckDefFailure(['for s:var in range(3)', 'echo 3'], 'E1254:')
4794 defcompile 4825 defcompile
4795 END 4826 END
4796 v9.CheckSourceSuccess(lines) 4827 v9.CheckSourceSuccess(lines)
4797 enddef 4828 enddef
4798 4829
4830 " Test for using defer without parenthesis for the function name
4831 def Test_defer_func_without_paren()
4832 var lines =<< trim END
4833 vim9script
4834 def Foo()
4835 defer Bar
4836 enddef
4837 defcompile
4838 END
4839 v9.CheckScriptFailure(lines, 'E107: Missing parentheses: Bar', 1)
4840 enddef
4841
4842 " Test for using defer without parenthesis for the function name
4843 def Test_defer_non_existing_func()
4844 var lines =<< trim END
4845 vim9script
4846 def Foo()
4847 defer Bar()
4848 enddef
4849 defcompile
4850 END
4851 v9.CheckScriptFailure(lines, 'E1001: Variable not found: Bar', 1)
4852 enddef
4853
4854 " Test for using defer with an invalid function name
4855 def Test_defer_invalid_func()
4856 var lines =<< trim END
4857 vim9script
4858 def Foo()
4859 var Abc = 10
4860 defer Abc()
4861 enddef
4862 defcompile
4863 END
4864 v9.CheckScriptFailure(lines, 'E129: Function name required', 2)
4865 enddef
4866
4867 " Test for using defer with an invalid argument to a function
4868 def Test_defer_invalid_func_arg()
4869 var lines =<< trim END
4870 vim9script
4871 def Bar(x: number)
4872 enddef
4873 def Foo()
4874 defer Bar(a)
4875 enddef
4876 defcompile
4877 END
4878 v9.CheckScriptFailure(lines, 'E1001: Variable not found: a', 1)
4879 enddef
4880
4881 " Test for using an non-existing type in a "for" statement.
4882 def Test_invalid_type_in_for()
4883 var lines =<< trim END
4884 vim9script
4885 def Foo()
4886 for b: x in range(10)
4887 endfor
4888 enddef
4889 defcompile
4890 END
4891 v9.CheckSourceFailure(lines, 'E1010: Type not recognized: x in range(10)', 1)
4892 enddef
4893
4894 " Test for using a line break between the variable name and the type in a for
4895 " statement.
4896 def Test_for_stmt_space_before_type()
4897 var lines =<< trim END
4898 vim9script
4899 def Foo()
4900 for a
4901 :number in range(10)
4902 endfor
4903 enddef
4904 defcompile
4905 END
4906 v9.CheckSourceFailure(lines, 'E1059: No white space allowed before colon: :number in range(10)', 2)
4907 enddef
4908
4799 " Keep this last, it messes up highlighting. 4909 " Keep this last, it messes up highlighting.
4800 def Test_substitute_cmd() 4910 def Test_substitute_cmd()
4801 new 4911 new
4802 setline(1, 'something') 4912 setline(1, 'something')
4803 :substitute(some(other( 4913 :substitute(some(other(