]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods v9.1.0286
authorYegappan Lakshmanan <yegappan@yahoo.com>
Tue, 9 Apr 2024 19:39:27 +0000 (21:39 +0200)
committerChristian Brabandt <cb@256bit.org>
Tue, 9 Apr 2024 19:39:27 +0000 (21:39 +0200)
Problem:  Vim9: E1027 with defcompile for abstract methods with
          non-void return types, but still compiles it
          (zzzyxwvut)
Solution: Don't compile abstract methods
          (Yegappan Lakshmanan)

fixes: #14443
closes: #14447

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 77a2102c2d69138d7047b2756c2b22dfbc51f160..6d6d1785104454c27b4e20e99bb1bae305ca5210 100644 (file)
@@ -10583,4 +10583,46 @@ def Test_lambda_block_in_class()
   v9.CheckScriptSuccess(lines)
 enddef
 
+" Test for defcompiling an abstract method
+def Test_abstract_method_defcompile()
+  # Compile an abstract class with abstract object methods
+  var lines =<< trim END
+    vim9script
+    abstract class A
+      abstract def Foo(): string
+      abstract def Bar(): list<string>
+    endclass
+    defcompile
+  END
+  v9.CheckScriptSuccess(lines)
+
+  # Compile a concrete object method in an abstract class
+  lines =<< trim END
+    vim9script
+    abstract class A
+      abstract def Foo(): string
+      abstract def Bar(): list<string>
+      def Baz(): string
+        pass
+      enddef
+    endclass
+    defcompile
+  END
+  v9.CheckScriptFailure(lines, 'E476: Invalid command: pass', 1)
+
+  # Compile a concrete class method in an abstract class
+  lines =<< trim END
+    vim9script
+    abstract class A
+      abstract def Foo(): string
+      abstract def Bar(): list<string>
+      static def Baz(): string
+        pass
+      enddef
+    endclass
+    defcompile
+  END
+  v9.CheckScriptFailure(lines, 'E476: Invalid command: pass', 1)
+enddef
+
 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
index d3fde434cc7b4ef09feef9b2d0b1bb510cfff8aa..4cece61ad67c86fd4401137462aaad9f2ad0937f 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    286,
 /**/
     285,
 /**/
index 11e952c7979bd863df5e0836716fbd4345fa57c1..a6b3ee2dc67fdb978d788c56be26e5ebb08b1020 100644 (file)
@@ -3723,7 +3723,9 @@ defcompile_class(class_T *cl)
        {
            ufunc_T *ufunc = loop == 1 ? cl->class_class_functions[i]
                                                : cl->class_obj_methods[i];
-           defcompile_function(ufunc, cl);
+           // Don't compile abstract methods
+           if (!IS_ABSTRACT_METHOD(ufunc))
+               defcompile_function(ufunc, cl);
        }
     }
 }