0
0
mirror of https://github.com/vim/vim.git synced 2025-07-04 23:07:33 -04:00

patch 9.1.1279: Vim9: null_object and null_class are no reserved names

Problem:  Vim9: null_object and null_class are no reserved names
Solution: Add null_object and null_class as reserved names.
          (Yegappan Lakshmanan)

closes: #17054

Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Yegappan Lakshmanan 2025-04-05 16:00:22 +02:00 committed by Christian Brabandt
parent d22f43111b
commit 8daae6fea9
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09
5 changed files with 43 additions and 19 deletions

View File

@ -1,4 +1,4 @@
*vim9class.txt* For Vim version 9.1. Last change: 2025 Feb 16 *vim9class.txt* For Vim version 9.1. Last change: 2025 Apr 05
VIM REFERENCE MANUAL by Bram Moolenaar VIM REFERENCE MANUAL by Bram Moolenaar
@ -641,8 +641,8 @@ class, then the type of the variable is set.
The following reserved keyword names cannot be used as an object or class The following reserved keyword names cannot be used as an object or class
variable name: "super", "this", "true", "false", "null", "null_blob", variable name: "super", "this", "true", "false", "null", "null_blob",
"null_dict", "null_function", "null_list", "null_partial", "null_string", "null_channel", "null_class", "null_dict", "null_function", "null_job",
"null_channel" and "null_job". "null_list", "null_object", "null_partial" and "null_string".
Extending a class ~ Extending a class ~
*extends* *extends*

View File

@ -326,6 +326,8 @@ def Test_reserved_name()
'null_list', 'null_list',
'null_partial', 'null_partial',
'null_string', 'null_string',
'null_object',
'null_class',
] + more_names ] + more_names
v9.CheckDefExecAndScriptFailure(['var ' .. name .. ' = 0'], 'E1034:') v9.CheckDefExecAndScriptFailure(['var ' .. name .. ' = 0'], 'E1034:')
v9.CheckDefExecAndScriptFailure(['var ' .. name .. ': bool'], 'E1034:') v9.CheckDefExecAndScriptFailure(['var ' .. name .. ': bool'], 'E1034:')

View File

@ -704,6 +704,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1279,
/**/ /**/
1278, 1278,
/**/ /**/

View File

@ -1119,36 +1119,52 @@ check_script_var_type(
} }
// words that cannot be used as a variable // words that cannot be used as a variable
// Keep this array sorted, as bsearch() is used to search this array.
static char *reserved[] = { static char *reserved[] = {
"true",
"false", "false",
"null", "null",
"null_blob", "null_blob",
"null_channel",
"null_class",
"null_dict", "null_dict",
"null_function", "null_function",
"null_job",
"null_list", "null_list",
"null_tuple", "null_object",
"null_partial", "null_partial",
"null_string", "null_string",
"null_channel", "null_tuple",
"null_job",
"super", "super",
"this", "this",
NULL "true",
}; };
/*
* String compare function used for bsearch()
*/
static int
comp_names(const void *s1, const void *s2)
{
return STRCMP(*(char **)s1, *(char **)s2);
}
/*
* Returns OK if "name" is not a reserved keyword. Otherwise returns FAIL.
*/
int int
check_reserved_name(char_u *name, int is_objm_access) check_reserved_name(char_u *name, int is_objm_access)
{ {
int idx; // "this" can be used in an object method
if (is_objm_access && STRCMP("this", name) == 0)
return OK;
for (idx = 0; reserved[idx] != NULL; ++idx) if (bsearch(&name, reserved, ARRAY_LENGTH(reserved),
if (STRCMP(reserved[idx], name) == 0 sizeof(reserved[0]), comp_names) != NULL)
&& !(STRCMP("this", name) == 0 && is_objm_access))
{ {
semsg(_(e_cannot_use_reserved_name_str), name); semsg(_(e_cannot_use_reserved_name_str), name);
return FAIL; return FAIL;
} }
return OK; return OK;
} }

View File

@ -333,6 +333,9 @@ tuple_type_add_types(
return OK; return OK;
} }
/*
* Get a list type, based on the member item type in "member_type".
*/
type_T * type_T *
get_list_type(type_T *member_type, garray_T *type_gap) get_list_type(type_T *member_type, garray_T *type_gap)
{ {
@ -367,9 +370,7 @@ get_list_type(type_T *member_type, garray_T *type_gap)
* "tuple_types_ga". * "tuple_types_ga".
*/ */
type_T * type_T *
get_tuple_type( get_tuple_type(garray_T *tuple_types_gap, garray_T *type_gap)
garray_T *tuple_types_gap,
garray_T *type_gap)
{ {
type_T *type; type_T *type;
type_T **tuple_types = tuple_types_gap->ga_data; type_T **tuple_types = tuple_types_gap->ga_data;
@ -397,6 +398,9 @@ get_tuple_type(
return type; return type;
} }
/*
* Get a dict type, based on the member item type in "member_type".
*/
type_T * type_T *
get_dict_type(type_T *member_type, garray_T *type_gap) get_dict_type(type_T *member_type, garray_T *type_gap)
{ {