]> granicus.if.org Git - vim/commitdiff
patch 8.2.0078: expanding <sfile> works differently the second time v8.2.0078
authorBram Moolenaar <Bram@vim.org>
Thu, 2 Jan 2020 13:31:22 +0000 (14:31 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 2 Jan 2020 13:31:22 +0000 (14:31 +0100)
Problem:    Expanding <sfile> works differently the second time.
Solution:   Keep the expanded name when redefining a function. (closes #5425)

src/testdir/test_vimscript.vim
src/userfunc.c
src/version.c

index 89112dead236d3f3835d507d2283ab2ce25f6efc..c890fb779ae7e96996dc50d0772f20a5f713a12c 100644 (file)
@@ -1642,6 +1642,23 @@ func Test_script_local_func()
   enew! | close
 endfunc
 
+func Test_script_expand_sfile()
+  let lines =<< trim END
+    func s:snr()
+      return expand('<sfile>')
+    endfunc
+    let g:result = s:snr()
+  END
+  call writefile(lines, 'Xexpand')
+  source Xexpand
+  call assert_match('<SNR>\d\+_snr', g:result)
+  source Xexpand
+  call assert_match('<SNR>\d\+_snr', g:result)
+
+  call delete('Xexpand')
+  unlet g:result
+endfunc
+
 func Test_compound_assignment_operators()
     " Test for number
     let x = 1
index a8bc34ae81603c5c4d82f1fd5747aa5c129b0c01..95862fe875f56791f66faaa20d544197021fc60e 100644 (file)
@@ -2572,9 +2572,13 @@ ex_function(exarg_T *eap)
            }
            else
            {
-               // redefine existing function
+               char_u *exp_name = fp->uf_name_exp;
+
+               // redefine existing function, keep the expanded name
                VIM_CLEAR(name);
+               fp->uf_name_exp = NULL;
                func_clear_items(fp);
+               fp->uf_name_exp = exp_name;
 #ifdef FEAT_PROFILE
                fp->uf_profiling = FALSE;
                fp->uf_prof_initialized = FALSE;
index 118dad505b6f5087423750d0f609c4b499251edd..4516eb71bc60df61a1e4f1808e6f633a58d559d7 100644 (file)
@@ -742,6 +742,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    78,
 /**/
     77,
 /**/