]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.2161: Vim9: not able to use imported interfaces and classes v9.0.2161
authorYegappan Lakshmanan <yegappan@yahoo.com>
Thu, 14 Dec 2023 18:59:45 +0000 (19:59 +0100)
committerChristian Brabandt <cb@256bit.org>
Thu, 14 Dec 2023 18:59:45 +0000 (19:59 +0100)
Problem:  Vim9: not able to use imported interfaces and classes
Solution: Detect imported class/interfaces names correclty

fixes:  #13661
closes: #13685

Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/testdir/test_vim9_class.vim
src/version.c
src/vim9class.c

index e0f5db6253d07d192f8e42bfa865fe9ea46919b7..c1965880cf1e7ea7606174c6afdf68768a941fad 100644 (file)
@@ -3030,6 +3030,62 @@ def Test_class_import()
   v9.CheckScriptSuccess(lines)
 enddef
 
+" Test for implementing an imported interface
+def Test_implement_imported_interface()
+  var lines =<< trim END
+    vim9script
+    export interface Imp_Intf1
+      def Fn1(): number
+    endinterface
+    export interface Imp_Intf2
+      def Fn2(): number
+    endinterface
+  END
+  writefile(lines, 'Ximportinterface.vim', 'D')
+
+  lines =<< trim END
+    vim9script
+    import './Ximportinterface.vim' as Xintf
+
+    class A implements Xintf.Imp_Intf1, Xintf.Imp_Intf2
+      def Fn1(): number
+        return 10
+      enddef
+      def Fn2(): number
+        return 20
+      enddef
+    endclass
+    var a = A.new()
+    assert_equal(10, a.Fn1())
+    assert_equal(20, a.Fn2())
+  END
+  v9.CheckScriptSuccess(lines)
+enddef
+
+" Test for extending an imported class
+def Test_extend_imported_class()
+  var lines =<< trim END
+    vim9script
+    export class Imp_C1
+      def Fn1(): number
+        return 5
+      enddef
+    endclass
+  END
+  writefile(lines, 'Xextendimportclass.vim', 'D')
+
+  lines =<< trim END
+    vim9script
+    import './Xextendimportclass.vim' as XClass
+
+    class A extends XClass.Imp_C1
+    endclass
+    var a = A.new()
+    assert_equal(5, a.Fn1())
+  END
+  v9.CheckScriptSuccess(lines)
+enddef
+
 def Test_abstract_class()
   var lines =<< trim END
     vim9script
index ad5bda644d8ecb60cb0d07a05cea30e60f59c739..a6a54f227083d52a1e91dcc0bad0edc7df83fcff 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2161,
 /**/
     2160,
 /**/
index 4b065c85905d4d13eec2c336bce5fc0fbb4e6817..2c5e1dffa349e71bfeba50c5b03ec6f319893334 100644 (file)
@@ -1304,6 +1304,24 @@ add_classfuncs_objmethods(
     return OK;
 }
 
+/*
+ * Return the end of the class name starting at "arg".  Valid characters in a
+ * class name are alphanumeric characters and "_".  Also handles imported class
+ * names.
+ */
+    static char_u *
+find_class_name_end(char_u *arg)
+{
+    char_u *end = arg;
+
+    while (ASCII_ISALNUM(*end) || *end == '_'
+           || (*end == '.' && (ASCII_ISALNUM(end[1]) || end[1] == '_')))
+       ++end;
+
+    return end;
+}
+
+
 /*
  * Handle ":class" and ":abstract class" up to ":endclass".
  * Handle ":interface" up to ":endinterface".
@@ -1383,7 +1401,8 @@ ex_class(exarg_T *eap)
                goto early_ret;
            }
            arg = skipwhite(arg + 7);
-           char_u *end = find_name_end(arg, NULL, NULL, FNE_CHECK_START);
+
+           char_u *end = find_class_name_end(arg);
            if (!IS_WHITE_OR_NUL(*end))
            {
                semsg(_(e_white_space_required_after_name_str), arg);
@@ -1413,8 +1432,7 @@ ex_class(exarg_T *eap)
 
            for (;;)
            {
-               char_u *impl_end = find_name_end(arg, NULL, NULL,
-                                                             FNE_CHECK_START);
+               char_u *impl_end = find_class_name_end(arg);
                if ((!IS_WHITE_OR_NUL(*impl_end) && *impl_end != ',')
                        || (*impl_end == ','
                            && !IS_WHITE_OR_NUL(*(impl_end + 1))))