diff options
Diffstat (limited to 'src/vim9script.c')
-rw-r--r-- | src/vim9script.c | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/src/vim9script.c b/src/vim9script.c index d40e334aef..85d601c7ae 100644 --- a/src/vim9script.c +++ b/src/vim9script.c @@ -412,6 +412,7 @@ handle_import( garray_T names; garray_T as_names; + tv.v_type = VAR_UNKNOWN; ga_init2(&names, sizeof(char_u *), 10); ga_init2(&as_names, sizeof(char_u *), 10); if (*arg == '{') @@ -496,14 +497,14 @@ handle_import( goto erret; } + // The name of the file can be an expression, which must evaluate to a + // string. arg = skipwhite_and_linebreak(arg + 4, evalarg); - tv.v_type = VAR_UNKNOWN; - // TODO: should we accept any expression? - if (*arg == '\'') - ret = eval_lit_string(&arg, &tv, TRUE); - else if (*arg == '"') - ret = eval_string(&arg, &tv, TRUE); - if (ret == FAIL || tv.vval.v_string == NULL || *tv.vval.v_string == NUL) + ret = eval0(arg, &tv, NULL, evalarg); + if (ret == FAIL) + goto erret; + if (tv.v_type != VAR_STRING + || tv.vval.v_string == NULL || *tv.vval.v_string == NUL) { emsg(_(e_invalid_string_after_from)); goto erret; @@ -524,10 +525,7 @@ handle_import( len = STRLEN(si->sn_name) - STRLEN(tail) + STRLEN(tv.vval.v_string) + 2; from_name = alloc((int)len); if (from_name == NULL) - { - clear_tv(&tv); goto erret; - } vim_strncpy(from_name, si->sn_name, tail - si->sn_name); add_pathsep(from_name); STRCAT(from_name, tv.vval.v_string); @@ -550,7 +548,6 @@ handle_import( from_name = alloc((int)len); if (from_name == NULL) { - clear_tv(&tv); goto erret; } vim_snprintf((char *)from_name, len, "import/%s", tv.vval.v_string); @@ -561,10 +558,8 @@ handle_import( if (res == FAIL || sid <= 0) { semsg(_(e_could_not_import_str), tv.vval.v_string); - clear_tv(&tv); goto erret; } - clear_tv(&tv); if (*arg_start == '*') { @@ -669,6 +664,7 @@ handle_import( } } erret: + clear_tv(&tv); ga_clear_strings(&names); ga_clear_strings(&as_names); return cmd_end; |