patch 9.1.1285: Vim9: no error message for missing method after "super."
Commit: https://github.com/vim/vim/commit/5ce1e4ad4aaad243de03f29b0b341532bc6c8866 Author: Yegappan Lakshmanan <yegap...@yahoo.com> Date: Mon Apr 7 21:09:18 2025 +0200 patch 9.1.1285: Vim9: no error message for missing method after "super." Problem: Vim9: no error message for missing method after "super." Solution: output an error message, add a few more tests (Yegappan Lakshmanan). closes: #17070 Signed-off-by: Yegappan Lakshmanan <yegap...@yahoo.com> Signed-off-by: Christian Brabandt <c...@256bit.org> diff --git a/src/testdir/test_expr.vim b/src/testdir/test_expr.vim index 41b54aac1..be95c6442 100644 --- a/src/testdir/test_expr.vim +++ b/src/testdir/test_expr.vim @@ -1060,6 +1060,16 @@ func Test_bitwise_shift() END call v9.CheckDefAndScriptSuccess(lines) + " Error in the second expression of "<<" + let lines =<< trim END + vim9script + def Fn() + var x = 1 << y + enddef + defcompile + END + call v9.CheckSourceFailure(lines, 'E1001: Variable not found: y') + let lines =<< trim END # Use in a lambda function const DivBy2Ref_A = (n: number): number => n >> 1 diff --git a/src/testdir/test_vim9_class.vim b/src/testdir/test_vim9_class.vim index 4b6cb81bb..4aa9bb3b3 100644 --- a/src/testdir/test_vim9_class.vim +++ b/src/testdir/test_vim9_class.vim @@ -1921,6 +1921,21 @@ def Test_class_member() END v9.CheckSourceFailure(lines, "E1004: White space required before and after '='", 3) + # Space is not allowed before the object member variable name + lines =<< trim END + vim9script + class A + var n: number = 10 + endclass + + def Fn() + var a = A.new() + var y = a. n + enddef + defcompile + END + v9.CheckSourceFailure(lines, "E1202: No white space allowed after '.': . n", 2) + # Access a non-existing member lines =<< trim END vim9script @@ -3469,6 +3484,39 @@ def Test_super_dispatch() assert_equal('A', TestA(C.new())) END v9.CheckSourceSuccess(lines) + + # Invoking a class method in the parent class using "super" should fail + lines =<< trim END + vim9script + + class A + static def Fn(): string + return 'A' + enddef + endclass + + class B extends A + static def Fn(): string + return super.Fn() + enddef + endclass + defcompile + END + v9.CheckSourceFailure(lines, 'E1325: Method "Fn" not found in class "B"') + + # Missing name after "super" keyword + lines =<< trim END + vim9script + class A + endclass + class B extends A + def Fn() + var x = super.() + enddef + endclass + defcompile + END + v9.CheckSourceFailure(lines, 'E1127: Missing name after dot', 1) enddef def Test_class_import() @@ -12454,6 +12502,24 @@ def Test_super_keyword() END v9.CheckSourceSuccess(lines) + # Using 'super' to access an static class variable in the parent should fail + lines =<< trim END + vim9script + + class A + static var foo: string = 'xxx' + endclass + + class B extends A + def GetString(): string + return super.foo + enddef + endclass + + defcompile + END + v9.CheckSourceFailure(lines, 'E1326: Variable "foo" not found in object "B"') + # Using super to access an overriden method in the parent class lines =<< trim END vim9script @@ -12980,6 +13046,13 @@ def Test_object_of_class_type() var x: object<any,any> END v9.CheckSourceFailure(lines, 'E488: Trailing characters: ,any>') + + lines =<< trim END + var x: object<number> + END + v9.CheckSourceDefAndScriptFailure(lines, [ + \ 'E1353: Class name not found: <number>', + \ 'E1353: Class name not found: <number>']) enddef " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim index 8456037c7..698091361 100644 --- a/src/testdir/test_vim9_script.vim +++ b/src/testdir/test_vim9_script.vim @@ -4055,6 +4055,22 @@ def Test_error_in_autoload_script() &rtp = save_rtp enddef +" Test for sourcing a Vim9 script with a function script variable and "noclear". +" The type for the variable is dynamically allocated and should be freed. +def Test_source_func_script_var() + var lines =<< trim END + vim9script noclear + var Fn: func(list<any>): number + Fn = function('min') + assert_equal(2, Fn([4, 2])) + END + new + setline(1, lines) + source + source + bw! +enddef + def Test_error_in_autoload_script_foldexpr() var save_rtp = &rtp mkdir('Xvim/autoload', 'pR') diff --git a/src/version.c b/src/version.c index 8e39db916..466fdd5c2 100644 --- a/src/version.c +++ b/src/version.c @@ -704,6 +704,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1285, /**/ 1284, /**/ diff --git a/src/vim9expr.c b/src/vim9expr.c index 0ceff0b85..40c5fcc72 100644 --- a/src/vim9expr.c +++ b/src/vim9expr.c @@ -404,7 +404,10 @@ compile_class_object_index(cctx_T *cctx, char_u **arg, type_T *type) char_u *name = *arg; char_u *name_end = find_name_end(name, NULL, NULL, FNE_CHECK_START); if (name_end == name) + { + emsg(_(e_missing_name_after_dot)); return FAIL; + } size_t len = name_end - name; if (*name_end == '(') -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/vim_dev/E1u1rw3-006ZgV-MP%40256bit.org.