]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1033: Vim9: compiling abstract method fails without return v9.1.1034
authorErnie Rael <errael@raelity.com>
Sat, 18 Jan 2025 16:26:39 +0000 (17:26 +0100)
committerChristian Brabandt <cb@256bit.org>
Sat, 18 Jan 2025 16:29:06 +0000 (17:29 +0100)
Problem:  Vim9: compiling abstract method fails without return
          (Aliaksei Budavei)
Solution: don't require return for an abstract method
          (Ernie Rael)

fixes: #15432
related: ##15441
closes: #16469

Signed-off-by: Ernie Rael <errael@raelity.com>
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/vim9compile.c

index fc0edeb5bab2483705799c840ac06ac43519dd11..cac8b63c7eb508a2d3c17b9fd7b9e048cd9244b6 100644 (file)
@@ -6458,6 +6458,39 @@ def Test_abstract_method()
     assert_equal('foo', A.Foo())
   END
   v9.CheckSourceSuccess(lines)
+
+    # Invoke method returning a value through the abstract class. See #15432.
+  lines =<< trim END
+    vim9script
+
+    abstract class A
+        abstract def String(): string
+    endclass
+
+    class B extends A
+        def String(): string
+            return 'B'
+        enddef
+    endclass
+
+    def F(o: A)
+        assert_equal('B', o.String())
+    enddef
+    F(B.new())
+  END
+  v9.CheckSourceSuccess(lines)
+
+  # Invoke abstract method returning a value does not compile
+  lines =<< trim END
+    vim9script
+
+    abstract class A
+      abstract def String(): string
+        return 'X'
+      enddef
+    endclass
+  END
+  v9.CheckScriptFailure(lines, "E1318: Not a valid command in a class: return 'X'")
 enddef
 
 " Test for calling a class method from a subclass
index 6e6b651a1cb675a10fcaa4964943cf4b41030238..ba41159774aa5867d76f38dcf9db056a26d201d3 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1034,
 /**/
     1033,
 /**/
index fa02871e8b50cc81a54c9d29efcfce9b42a1ce68..338415e85fddfde345bf930e32133e08dcba325c 100644 (file)
@@ -4917,9 +4917,10 @@ compile_def_function(
            goto erret;
     ufunc->uf_args_visible = ufunc->uf_args.ga_len;
 
-    // Compiling a function in an interface is done to get the function type.
-    // No code is actually compiled.
-    if (ufunc->uf_class != NULL && IS_INTERFACE(ufunc->uf_class))
+    // Compiling an abstract method or a function in an interface is done to
+    // get the function type.  No code is actually compiled.
+    if (ufunc->uf_class != NULL && (IS_INTERFACE(ufunc->uf_class)
+                                               || IS_ABSTRACT_METHOD(ufunc)))
     {
        ufunc->uf_def_status = UF_NOT_COMPILED;
        ret = OK;