forked from aniani/vim
patch 9.0.2182: Vim9: need a way to reserve future extension
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>
This commit is contained in:
parent
cc944b1452
commit
ff6f0d5c38
@ -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: >
|
||||
|
@ -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
|
||||
|
@ -704,6 +704,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
2182,
|
||||
/**/
|
||||
2181,
|
||||
/**/
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user