Skip to content

Commit 7c92e88

Browse files
erraelchrisbra
authored andcommitted
patch 9.1.1033: Vim9: compiling abstract method fails without return
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>
1 parent fef4be0 commit 7c92e88

3 files changed

Lines changed: 39 additions & 3 deletions

File tree

src/testdir/test_vim9_class.vim

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6458,6 +6458,39 @@ def Test_abstract_method()
64586458
assert_equal('foo', A.Foo())
64596459
END
64606460
v9.CheckSourceSuccess(lines)
6461+
6462+
# Invoke method returning a value through the abstract class. See #15432.
6463+
lines =<< trim END
6464+
vim9script
6465+
6466+
abstract class A
6467+
abstract def String(): string
6468+
endclass
6469+
6470+
class B extends A
6471+
def String(): string
6472+
return 'B'
6473+
enddef
6474+
endclass
6475+
6476+
def F(o: A)
6477+
assert_equal('B', o.String())
6478+
enddef
6479+
F(B.new())
6480+
END
6481+
v9.CheckSourceSuccess(lines)
6482+
6483+
# Invoke abstract method returning a value does not compile
6484+
lines =<< trim END
6485+
vim9script
6486+
6487+
abstract class A
6488+
abstract def String(): string
6489+
return 'X'
6490+
enddef
6491+
endclass
6492+
END
6493+
v9.CheckScriptFailure(lines, "E1318: Not a valid command in a class: return 'X'")
64616494
enddef
64626495

64636496
" Test for calling a class method from a subclass

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ static char *(features[]) =
704704

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
1034,
707709
/**/
708710
1033,
709711
/**/

src/vim9compile.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4917,9 +4917,10 @@ compile_def_function(
49174917
goto erret;
49184918
ufunc->uf_args_visible = ufunc->uf_args.ga_len;
49194919

4920-
// Compiling a function in an interface is done to get the function type.
4921-
// No code is actually compiled.
4922-
if (ufunc->uf_class != NULL && IS_INTERFACE(ufunc->uf_class))
4920+
// Compiling an abstract method or a function in an interface is done to
4921+
// get the function type. No code is actually compiled.
4922+
if (ufunc->uf_class != NULL && (IS_INTERFACE(ufunc->uf_class)
4923+
|| IS_ABSTRACT_METHOD(ufunc)))
49234924
{
49244925
ufunc->uf_def_status = UF_NOT_COMPILED;
49254926
ret = OK;

0 commit comments

Comments
 (0)