summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErnie Rael <errael@raelity.com>2024-08-14 14:53:55 +0200
committerChristian Brabandt <cb@256bit.org>2024-08-14 14:53:55 +0200
commit7477861e0d1d4bb168a65585c49c66e57b3ec636 (patch)
tree77db8e2093a89402281630cd350b1b20d01075bb
parentea76096fa98ac26c23703bffdc4d9b3dc8a94d7e (diff)
patch 9.1.0674: Vim9: compiling abstract method fails because of missing returnv9.1.0674
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>
-rw-r--r--src/testdir/test_vim9_class.vim21
-rw-r--r--src/version.c2
-rw-r--r--src/vim9compile.c5
3 files changed, 26 insertions, 2 deletions
diff --git a/src/testdir/test_vim9_class.vim b/src/testdir/test_vim9_class.vim
index 8791a5218d..702ec2609f 100644
--- a/src/testdir/test_vim9_class.vim
+++ b/src/testdir/test_vim9_class.vim
@@ -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
diff --git a/src/version.c b/src/version.c
index edde65f729..9bfca005dd 100644
--- a/src/version.c
+++ b/src/version.c
@@ -705,6 +705,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 674,
+/**/
673,
/**/
672,
diff --git a/src/vim9compile.c b/src/vim9compile.c
index ea305b7b34..de13f9bb49 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -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;