summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYegappan Lakshmanan <yegappan@yahoo.com>2023-12-21 16:46:18 +0100
committerChristian Brabandt <cb@256bit.org>2023-12-21 16:46:18 +0100
commitff6f0d5c38e81f742e1161c1504fc6b8e45d9a1e (patch)
tree5b38ef43eb96593691588f9605281bd3145628d3
parentcc944b1452547145cdd947a37c75fce695d8571e (diff)
patch 9.0.2182: Vim9: need a way to reserve future extensionv9.0.2182
Problem: Vim9: need a way to reserve future extension Solution: reserve double underscore prefix for future use (Yegappan Lakshmanan) related: #13238 closes: #13742 Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
-rw-r--r--runtime/doc/vim9class.txt3
-rw-r--r--src/testdir/test_vim9_class.vim27
-rw-r--r--src/version.c2
-rw-r--r--src/vim9class.c9
-rw-r--r--src/vim9compile.c24
5 files changed, 53 insertions, 12 deletions
diff --git a/runtime/doc/vim9class.txt b/runtime/doc/vim9class.txt
index 4dc67bd872..929597c70b 100644
--- a/runtime/doc/vim9class.txt
+++ b/runtime/doc/vim9class.txt
@@ -364,6 +364,9 @@ super class. Depending on the class where the member is used the
corresponding class member will be used. The type of the class member in a
child class can be different from that in the super class.
+The double underscore (__) prefix for a class or object method name is
+reserved for future use.
+
*object-final-variable* *E1409*
The |:final| keyword can be used to make a class or object variable a
constant. Examples: >
diff --git a/src/testdir/test_vim9_class.vim b/src/testdir/test_vim9_class.vim
index c28716aa1b..e2c61b03b7 100644
--- a/src/testdir/test_vim9_class.vim
+++ b/src/testdir/test_vim9_class.vim
@@ -9659,4 +9659,31 @@ def Test_const_class_object_variable()
v9.CheckSourceFailure(lines, 'E1022: Type or initialization required', 3)
enddef
+" Test for using double underscore prefix in a class/object method name.
+def Test_method_double_underscore_prefix()
+ # class method
+ var lines =<< trim END
+ vim9script
+ class A
+ static def __foo()
+ echo "foo"
+ enddef
+ endclass
+ defcompile
+ END
+ v9.CheckSourceFailure(lines, 'E1034: Cannot use reserved name __foo()', 3)
+
+ # object method
+ lines =<< trim END
+ vim9script
+ class A
+ def __foo()
+ echo "foo"
+ enddef
+ endclass
+ defcompile
+ END
+ v9.CheckSourceFailure(lines, 'E1034: Cannot use reserved name __foo()', 3)
+enddef
+
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
diff --git a/src/version.c b/src/version.c
index 316e638920..6120c538a7 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 */
/**/
+ 2182,
+/**/
2181,
/**/
2180,
diff --git a/src/vim9class.c b/src/vim9class.c
index ec1bb86d09..e5d9aeb4ba 100644
--- a/src/vim9class.c
+++ b/src/vim9class.c
@@ -1774,6 +1774,15 @@ early_ret:
break;
}
+ if (*p == '_' && *(p + 1) == '_')
+ {
+ // double underscore prefix for a method name is currently
+ // reserved. This could be used in the future to support
+ // object methods called by Vim builtin functions.
+ semsg(_(e_cannot_use_reserved_name_str), p);
+ break;
+ }
+
CLEAR_FIELD(ea);
ea.cmd = line;
ea.arg = p;
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 17a3b6a5c3..868acb4698 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -2263,12 +2263,12 @@ compile_load_lhs_with_index(lhs_T *lhs, char_u *var_start, cctx_T *cctx)
// "this.value": load "this" object and get the value at index for an
// object or class member get the type of the member.
// Also for "obj.value".
- char_u *dot = vim_strchr(var_start, '.');
- if (dot == NULL)
- {
- semsg(_(e_missing_dot_after_object_str), lhs->lhs_name);
- return FAIL;
- }
+ char_u *dot = vim_strchr(var_start, '.');
+ if (dot == NULL)
+ {
+ semsg(_(e_missing_dot_after_object_str), lhs->lhs_name);
+ return FAIL;
+ }
class_T *cl = lhs->lhs_type->tt_class;
type_T *type = oc_member_type(cl, TRUE, dot + 1,
@@ -2295,12 +2295,12 @@ compile_load_lhs_with_index(lhs_T *lhs, char_u *var_start, cctx_T *cctx)
else if (lhs->lhs_type->tt_type == VAR_CLASS)
{
// "<classname>.value": load class variable "classname.value"
- char_u *dot = vim_strchr(var_start, '.');
- if (dot == NULL)
- {
- check_type_is_value(lhs->lhs_type);
- return FAIL;
- }
+ char_u *dot = vim_strchr(var_start, '.');
+ if (dot == NULL)
+ {
+ check_type_is_value(lhs->lhs_type);
+ return FAIL;
+ }
class_T *cl = lhs->lhs_type->tt_class;
ocmember_T *m = class_member_lookup(cl, dot + 1,