Skip to content

Commit ef9e3f8

Browse files
yegappanchrisbra
authored andcommitted
patch 9.0.2084: Vim9: abstract static methods are possible
Problem: Vim9: abstract static methods are possible Solution: Disallow abstract static methods fixes: #13462 closes: #13466 Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 1858e2b commit ef9e3f8

5 files changed

Lines changed: 25 additions & 26 deletions

File tree

runtime/doc/vim9class.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,8 @@ prefix when defining the method: >
411411
abstract static def SetColor()
412412
endclass
413413
<
414+
A static method in an abstract class cannot be an abstract method.
415+
414416
*E1373*
415417
A class extending the abstract class must implement all the abstract methods.
416418
The signature (arguments, argument types and return type) must be exactly the

src/errors.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3494,8 +3494,8 @@ EXTERN char e_duplicate_variable_str[]
34943494
INIT(= N_("E1369: Duplicate variable: %s"));
34953495
EXTERN char e_cannot_define_new_method_as_static[]
34963496
INIT(= N_("E1370: Cannot define a \"new\" method as static"));
3497-
EXTERN char e_abstract_must_be_followed_by_def_or_static[]
3498-
INIT(= N_("E1371: Abstract must be followed by \"def\" or \"static\""));
3497+
EXTERN char e_abstract_must_be_followed_by_def[]
3498+
INIT(= N_("E1371: Abstract must be followed by \"def\""));
34993499
EXTERN char e_abstract_method_in_concrete_class[]
35003500
INIT(= N_("E1372: Abstract method \"%s\" cannot be defined in a concrete class"));
35013501
EXTERN char e_abstract_method_str_not_found[]

src/testdir/test_vim9_class.vim

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def Test_class_basic()
3535
END
3636
v9.CheckSourceFailure(lines, 'E475: Invalid argument: noclass Something', 2)
3737

38-
# Only the completed word "class" should be recognized
38+
# Only the complete word "class" should be recognized
3939
lines =<< trim END
4040
vim9script
4141
abstract classy Something
@@ -4186,8 +4186,8 @@ enddef
41864186
def Test_lockvar_islocked()
41874187
# Can't lock class/object variable
41884188
# Lock class/object variable's value
4189-
# Lock item of variabl's value (a list item)
4190-
# varible is at index 1 within class/object
4189+
# Lock item of variable's value (a list item)
4190+
# variable is at index 1 within class/object
41914191
var lines =<< trim END
41924192
vim9script
41934193

@@ -5585,22 +5585,16 @@ def Test_abstract_method()
55855585
abstract this.val = 10
55865586
endclass
55875587
END
5588-
v9.CheckSourceFailure(lines, 'E1371: Abstract must be followed by "def" or "static"', 3)
5588+
v9.CheckSourceFailure(lines, 'E1371: Abstract must be followed by "def"', 3)
55895589

55905590
# Use a static abstract method
55915591
lines =<< trim END
55925592
vim9script
55935593
abstract class A
55945594
abstract static def Foo(): number
55955595
endclass
5596-
class B extends A
5597-
static def Foo(): number
5598-
return 4
5599-
enddef
5600-
endclass
5601-
assert_equal(4, B.Foo())
56025596
END
5603-
v9.CheckSourceSuccess(lines)
5597+
v9.CheckSourceFailure(lines, 'E1371: Abstract must be followed by "def"', 3)
56045598

56055599
# Type mismatch between abstract method and concrete method
56065600
lines =<< trim END
@@ -5616,17 +5610,6 @@ def Test_abstract_method()
56165610
END
56175611
v9.CheckSourceFailure(lines, 'E1383: Method "Foo": type mismatch, expected func(string, number): list<number> but got func(number, string): list<string>', 9)
56185612

5619-
# Use an abstract class to invoke an abstract method
5620-
# FIXME: This should fail
5621-
lines =<< trim END
5622-
vim9script
5623-
abstract class A
5624-
abstract static def Foo()
5625-
endclass
5626-
A.Foo()
5627-
END
5628-
v9.CheckSourceSuccess(lines)
5629-
56305613
# Invoke an abstract method from a def function
56315614
lines =<< trim END
56325615
vim9script
@@ -5645,6 +5628,18 @@ def Test_abstract_method()
56455628
Bar(b)
56465629
END
56475630
v9.CheckSourceSuccess(lines)
5631+
5632+
# Use a static method in an abstract class
5633+
lines =<< trim END
5634+
vim9script
5635+
abstract class A
5636+
static def Foo(): string
5637+
return 'foo'
5638+
enddef
5639+
endclass
5640+
assert_equal('foo', A.Foo())
5641+
END
5642+
v9.CheckSourceSuccess(lines)
56485643
enddef
56495644

56505645
" 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+
2084,
707709
/**/
708710
2083,
709711
/**/

src/vim9class.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,9 +1571,9 @@ ex_class(exarg_T *eap)
15711571

15721572
abstract_method = TRUE;
15731573
p = skipwhite(pa + 8);
1574-
if (STRNCMP(p, "def", 3) != 0 && STRNCMP(p, "static", 6) != 0)
1574+
if (STRNCMP(p, "def", 3) != 0)
15751575
{
1576-
emsg(_(e_abstract_must_be_followed_by_def_or_static));
1576+
emsg(_(e_abstract_must_be_followed_by_def));
15771577
break;
15781578
}
15791579
}

0 commit comments

Comments
 (0)