Mercurial > vim
comparison src/vim9compile.c @ 21598:7b5b9558500a v8.2.1349
patch 8.2.1349: Vim9: can define a function with the name of an import
Commit: https://github.com/vim/vim/commit/eef2102e20d24f5fbd1c9f53c7a35df61585c5ab
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Aug 1 22:16:43 2020 +0200
patch 8.2.1349: Vim9: can define a function with the name of an import
Problem: Vim9: can define a function with the name of an import.
Solution: Disallow using an existing name. (closes https://github.com/vim/vim/issues/6585)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 01 Aug 2020 22:30:04 +0200 |
parents | d0c76ce48326 |
children | 7028f45bf0ea |
comparison
equal
deleted
inserted
replaced
21597:b26b1529cb9b | 21598:7b5b9558500a |
---|---|
292 check_defined(char_u *p, size_t len, cctx_T *cctx) | 292 check_defined(char_u *p, size_t len, cctx_T *cctx) |
293 { | 293 { |
294 if (lookup_script(p, len) == OK | 294 if (lookup_script(p, len) == OK |
295 || (cctx != NULL | 295 || (cctx != NULL |
296 && (lookup_local(p, len, cctx) != NULL | 296 && (lookup_local(p, len, cctx) != NULL |
297 || find_imported(p, len, cctx) != NULL))) | 297 || lookup_arg(p, len, NULL, NULL, NULL, cctx) == OK)) |
298 { | 298 || find_imported(p, len, cctx) != NULL) |
299 semsg("E1073: imported name already defined: %s", p); | 299 { |
300 semsg(_(e_already_defined), p); | |
300 return FAIL; | 301 return FAIL; |
301 } | 302 } |
302 return OK; | 303 return OK; |
303 } | 304 } |
304 | 305 |
4897 compile_nested_function(exarg_T *eap, cctx_T *cctx) | 4898 compile_nested_function(exarg_T *eap, cctx_T *cctx) |
4898 { | 4899 { |
4899 int is_global = *eap->arg == 'g' && eap->arg[1] == ':'; | 4900 int is_global = *eap->arg == 'g' && eap->arg[1] == ':'; |
4900 char_u *name_start = eap->arg; | 4901 char_u *name_start = eap->arg; |
4901 char_u *name_end = to_name_end(eap->arg, is_global); | 4902 char_u *name_end = to_name_end(eap->arg, is_global); |
4902 char_u *name = get_lambda_name(); | 4903 char_u *lambda_name; |
4903 lvar_T *lvar; | 4904 lvar_T *lvar; |
4904 ufunc_T *ufunc; | 4905 ufunc_T *ufunc; |
4905 int r; | 4906 int r; |
4907 | |
4908 if (check_defined(name_start, name_end - name_start, cctx) == FAIL) | |
4909 return NULL; | |
4906 | 4910 |
4907 eap->arg = name_end; | 4911 eap->arg = name_end; |
4908 eap->getline = exarg_getline; | 4912 eap->getline = exarg_getline; |
4909 eap->cookie = cctx; | 4913 eap->cookie = cctx; |
4910 eap->skip = cctx->ctx_skip == SKIP_YES; | 4914 eap->skip = cctx->ctx_skip == SKIP_YES; |
4911 eap->forceit = FALSE; | 4915 eap->forceit = FALSE; |
4912 ufunc = def_function(eap, name); | 4916 lambda_name = get_lambda_name(); |
4917 ufunc = def_function(eap, lambda_name); | |
4913 | 4918 |
4914 if (ufunc == NULL) | 4919 if (ufunc == NULL) |
4915 return NULL; | 4920 return NULL; |
4916 if (ufunc->uf_def_status == UF_TO_BE_COMPILED | 4921 if (ufunc->uf_def_status == UF_TO_BE_COMPILED |
4917 && compile_def_function(ufunc, TRUE, cctx) == FAIL) | 4922 && compile_def_function(ufunc, TRUE, cctx) == FAIL) |
4923 name_end - name_start - 2); | 4928 name_end - name_start - 2); |
4924 | 4929 |
4925 if (func_name == NULL) | 4930 if (func_name == NULL) |
4926 r = FAIL; | 4931 r = FAIL; |
4927 else | 4932 else |
4928 r = generate_NEWFUNC(cctx, name, func_name); | 4933 r = generate_NEWFUNC(cctx, lambda_name, func_name); |
4929 } | 4934 } |
4930 else | 4935 else |
4931 { | 4936 { |
4932 // Define a local variable for the function reference. | 4937 // Define a local variable for the function reference. |
4933 lvar = reserve_local(cctx, name_start, name_end - name_start, | 4938 lvar = reserve_local(cctx, name_start, name_end - name_start, |
4934 TRUE, ufunc->uf_func_type); | 4939 TRUE, ufunc->uf_func_type); |
4940 if (lvar == NULL) | |
4941 return NULL; | |
4935 if (generate_FUNCREF(cctx, ufunc->uf_dfunc_idx) == FAIL) | 4942 if (generate_FUNCREF(cctx, ufunc->uf_dfunc_idx) == FAIL) |
4936 return NULL; | 4943 return NULL; |
4937 r = generate_STORE(cctx, ISN_STORE, lvar->lv_idx, NULL); | 4944 r = generate_STORE(cctx, ISN_STORE, lvar->lv_idx, NULL); |
4938 } | 4945 } |
4939 | 4946 |