-*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
The following reserved keyword names cannot be used as an object or class
variable name: "super", "this", "true", "false", "null", "null_blob",
-"null_dict", "null_function", "null_list", "null_partial", "null_string",
-"null_channel" and "null_job".
+"null_channel", "null_class", "null_dict", "null_function", "null_job",
+"null_list", "null_object", "null_partial" and "null_string".
Extending a class ~
*extends*
'null_list',
'null_partial',
'null_string',
+ 'null_object',
+ 'null_class',
] + more_names
v9.CheckDefExecAndScriptFailure(['var ' .. name .. ' = 0'], 'E1034:')
v9.CheckDefExecAndScriptFailure(['var ' .. name .. ': bool'], 'E1034:')
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1279,
/**/
1278,
/**/
}
// words that cannot be used as a variable
+// Keep this array sorted, as bsearch() is used to search this array.
static char *reserved[] = {
- "true",
"false",
"null",
"null_blob",
+ "null_channel",
+ "null_class",
"null_dict",
"null_function",
+ "null_job",
"null_list",
- "null_tuple",
+ "null_object",
"null_partial",
"null_string",
- "null_channel",
- "null_job",
+ "null_tuple",
"super",
"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
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;
+
+ if (bsearch(&name, reserved, ARRAY_LENGTH(reserved),
+ sizeof(reserved[0]), comp_names) != NULL)
+ {
+ semsg(_(e_cannot_use_reserved_name_str), name);
+ return FAIL;
+ }
- for (idx = 0; reserved[idx] != NULL; ++idx)
- if (STRCMP(reserved[idx], name) == 0
- && !(STRCMP("this", name) == 0 && is_objm_access))
- {
- semsg(_(e_cannot_use_reserved_name_str), name);
- return FAIL;
- }
return OK;
}
return OK;
}
+/*
+ * Get a list type, based on the member item type in "member_type".
+ */
type_T *
get_list_type(type_T *member_type, garray_T *type_gap)
{
* "tuple_types_ga".
*/
type_T *
-get_tuple_type(
- garray_T *tuple_types_gap,
- garray_T *type_gap)
+get_tuple_type(garray_T *tuple_types_gap, garray_T *type_gap)
{
type_T *type;
type_T **tuple_types = tuple_types_gap->ga_data;
return type;
}
+/*
+ * Get a dict type, based on the member item type in "member_type".
+ */
type_T *
get_dict_type(type_T *member_type, garray_T *type_gap)
{