]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0674: Vim9: compiling abstract method fails because of missing return v9.1.0674
authorErnie Rael <errael@raelity.com>
Wed, 14 Aug 2024 12:53:55 +0000 (14:53 +0200)
committerChristian Brabandt <cb@256bit.org>
Wed, 14 Aug 2024 12:53:55 +0000 (14:53 +0200)
Problem:  Vim9: compiling abstract method fails because of missing
          return (Aliaksei Budavei)
Solution: don't require a return statement for an abstract method when
          compiling (Ernie Rael)

fixes: #15432
closes: #15441

Signed-off-by: Ernie Rael <errael@raelity.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/testdir/test_vim9_class.vim
src/version.c
src/vim9compile.c

index 8791a5218d86059cfbf4ff4c0889a592f2ccb35c..702ec2609f9be80c21c92a9dd5355be7044e531e 100644 (file)
@@ -6264,6 +6264,27 @@ 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)
 enddef
 
 " Test for calling a class method from a subclass
index edde65f7295930893d57bcd32df3959f796301e6..9bfca005ddb4f14dc91932a65b67bd101f3203d4 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    674,
 /**/
     673,
 /**/
index ea305b7b34bb5213e7f2d1d507a2f6493c641af5..de13f9bb49fd3a9149fd16a7b687f56ae78e37f5 100644 (file)
@@ -4120,8 +4120,9 @@ compile_def_function(
     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))
+    // No code is actually compiled. Same goes for an abstract method.
+    if ((ufunc->uf_class != NULL && IS_INTERFACE(ufunc->uf_class))
+       || IS_ABSTRACT_METHOD(ufunc))
     {
        ufunc->uf_def_status = UF_NOT_COMPILED;
        ret = OK;