Mercurial > vim
comparison src/vim9script.c @ 20840:0600ab7b9f09 v8.2.0972
patch 8.2.0972: Vim9 script variable declarations need a type
Commit: https://github.com/vim/vim/commit/c82a5b5da5eab15bc35115545b639fb590272ad7
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jun 13 18:09:19 2020 +0200
patch 8.2.0972: Vim9 script variable declarations need a type
Problem: Vim9 script variable declarations need a type.
Solution: Make "let var: type" declare a script-local variable.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 13 Jun 2020 18:15:03 +0200 |
parents | 9faab49c880f |
children | bacc2ab11810 |
comparison
equal
deleted
inserted
replaced
20839:7c1e92b152ed | 20840:0600ab7b9f09 |
---|---|
432 } | 432 } |
433 } | 433 } |
434 return cmd_end; | 434 return cmd_end; |
435 } | 435 } |
436 | 436 |
437 /* | |
438 * Declare a script-local variable without init: "let var: type". | |
439 * "const" is an error since the value is missing. | |
440 * Returns a pointer to after the type. | |
441 */ | |
442 char_u * | |
443 vim9_declare_scriptvar(exarg_T *eap, char_u *arg) | |
444 { | |
445 char_u *p; | |
446 char_u *name; | |
447 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); | |
448 type_T *type; | |
449 int called_emsg_before = called_emsg; | |
450 typval_T init_tv; | |
451 | |
452 if (eap->cmdidx == CMD_const) | |
453 { | |
454 emsg(_(e_const_req_value)); | |
455 return arg + STRLEN(arg); | |
456 } | |
457 | |
458 // Check for valid starting character. | |
459 if (!eval_isnamec1(*arg)) | |
460 { | |
461 semsg(_(e_invarg2), arg); | |
462 return arg + STRLEN(arg); | |
463 } | |
464 | |
465 for (p = arg + 1; *p != NUL && *p != ':' && eval_isnamec(*p); | |
466 MB_PTR_ADV(p)) | |
467 ; | |
468 | |
469 if (*p != ':') | |
470 { | |
471 emsg(_(e_type_req)); | |
472 return arg + STRLEN(arg); | |
473 } | |
474 name = vim_strnsave(arg, p - arg); | |
475 | |
476 // parse type | |
477 p = skipwhite(p + 1); | |
478 type = parse_type(&p, &si->sn_type_list); | |
479 if (called_emsg != called_emsg_before) | |
480 return p; | |
481 | |
482 // Create the variable with 0/NULL value. | |
483 CLEAR_FIELD(init_tv); | |
484 init_tv.v_type = type->tt_type; | |
485 set_var_const(name, type, &init_tv, FALSE, 0); | |
486 | |
487 vim_free(name); | |
488 return p; | |
489 } | |
490 | |
491 | |
437 #endif // FEAT_EVAL | 492 #endif // FEAT_EVAL |