Skip to content

Commit 2b358ad

Browse files
yegappanchrisbra
authored andcommitted
patch 9.0.2085: Vim9: abstract can be used in interface
Problem: Vim9: abstract can be used in interface Solution: Disallow the use of abstract in an interface fixes: #13456 closes: #13464 Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent ef9e3f8 commit 2b358ad

4 files changed

Lines changed: 42 additions & 18 deletions

File tree

src/errors.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3560,8 +3560,10 @@ EXTERN char e_using_typealias_as_string[]
35603560
INIT(= N_("E1402: Using type alias \"%s\" as a String"));
35613561
EXTERN char e_using_typealias_as_value[]
35623562
INIT(= N_("E1403: Type alias \"%s\" cannot be used as a value"));
3563+
EXTERN char e_abstract_cannot_be_used_in_interface[]
3564+
INIT(= N_("E1404: Abstract cannot be used in an interface"));
35633565
#endif
3564-
// E1404 - E1499 unused (reserved for Vim9 class support)
3566+
// E1405 - E1499 unused (reserved for Vim9 class support)
35653567
EXTERN char e_cannot_mix_positional_and_non_positional_str[]
35663568
INIT(= N_("E1500: Cannot mix positional and non-positional arguments: %s"));
35673569
EXTERN char e_fmt_arg_nr_unused_str[]

src/testdir/test_vim9_class.vim

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5567,7 +5567,26 @@ def Test_abstract_method()
55675567
enddef
55685568
endclass
55695569
END
5570-
v9.CheckSourceSuccess(lines)
5570+
v9.CheckSourceFailure(lines, 'E1404: Abstract cannot be used in an interface', 3)
5571+
5572+
# Use abstract static method in an interface
5573+
lines =<< trim END
5574+
vim9script
5575+
interface A
5576+
abstract static def Foo()
5577+
enddef
5578+
endinterface
5579+
END
5580+
v9.CheckSourceFailure(lines, 'E1404: Abstract cannot be used in an interface', 3)
5581+
5582+
# Use abstract static variable in an interface
5583+
lines =<< trim END
5584+
vim9script
5585+
interface A
5586+
abstract static foo: number = 10
5587+
endinterface
5588+
END
5589+
v9.CheckSourceFailure(lines, 'E1404: Abstract cannot be used in an interface', 3)
55715590

55725591
# Abbreviate the "abstract" keyword
55735592
lines =<< trim END

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

src/vim9class.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,26 +1557,27 @@ ex_class(exarg_T *eap)
15571557
break;
15581558
}
15591559

1560+
p = skipwhite(pa + 8);
1561+
if (STRNCMP(p, "def", 3) != 0 && STRNCMP(p, "static", 6) != 0)
1562+
{
1563+
emsg(_(e_abstract_must_be_followed_by_def_or_static));
1564+
break;
1565+
}
1566+
15601567
if (!is_class)
1561-
// ignore "abstract" in an interface (as all the methods in an
1562-
// interface are abstract.
1563-
p = skipwhite(pa + 8);
1564-
else
15651568
{
1566-
if (!is_abstract)
1567-
{
1568-
semsg(_(e_abstract_method_in_concrete_class), pa);
1569-
break;
1570-
}
1569+
// "abstract" not supported in an interface
1570+
emsg(_(e_abstract_cannot_be_used_in_interface));
1571+
break;
1572+
}
15711573

1572-
abstract_method = TRUE;
1573-
p = skipwhite(pa + 8);
1574-
if (STRNCMP(p, "def", 3) != 0)
1575-
{
1576-
emsg(_(e_abstract_must_be_followed_by_def));
1577-
break;
1578-
}
1574+
if (!is_abstract)
1575+
{
1576+
semsg(_(e_abstract_method_in_concrete_class), pa);
1577+
break;
15791578
}
1579+
1580+
abstract_method = TRUE;
15801581
}
15811582

15821583
int has_static = FALSE;

0 commit comments

Comments
 (0)