]> granicus.if.org Git - vim/commitdiff
patch 8.2.2809: Vim9: :def function compilation fails when using :legacy v8.2.2809
authorBram Moolenaar <Bram@vim.org>
Sun, 25 Apr 2021 11:54:42 +0000 (13:54 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 25 Apr 2021 11:54:42 +0000 (13:54 +0200)
Problem:    Vim9: :def function compilation fails when using :legacy.
Solution:   Reset CMOD_LEGACY when compiling a function. (closes #8137)

src/testdir/test_vim9_func.vim
src/version.c
src/vim9compile.c

index 230de20e376c7768ff26206ddc0a732c41df09f8..5bfad6bcb4c86319471f9b44de20f2bcaee8793e 100644 (file)
@@ -2167,10 +2167,20 @@ enddef
 
 def Test_legacy_lambda()
   legacy echo {x -> 'hello ' .. x}('foo')
+
   var lines =<< trim END
       echo {x -> 'hello ' .. x}('foo')
   END
   CheckDefAndScriptFailure(lines, 'E720:')
+
+  lines =<< trim END
+      vim9script
+      def Func()
+        echo (() => 'no error')()
+      enddef
+      legacy call s:Func()
+  END
+  CheckScriptSuccess(lines)
 enddef
 
 def DoFilterThis(a: string): list<string>
index 4b0b1cc3045fa7e6bd3754832a93bfdcae0a80e8..d235e94ebbeab9ad69f86eca0663739fdc86400f 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2809,
 /**/
     2808,
 /**/
index a3154c3316adb228d64d02ae697c5c4925402e77..8589cec6009428775fd8a9772b93b83329b1672a 100644 (file)
@@ -8767,6 +8767,7 @@ compile_def_function(
     int                ret = FAIL;
     sctx_T     save_current_sctx = current_sctx;
     int                save_estack_compiling = estack_compiling;
+    int                save_cmod_flags = cmdmod.cmod_flags;
     int                do_estack_push;
     int                new_def_function = FALSE;
 #ifdef FEAT_PROFILE
@@ -8811,6 +8812,9 @@ compile_def_function(
     current_sctx = ufunc->uf_script_ctx;
     current_sctx.sc_version = SCRIPT_VERSION_VIM9;
 
+    // Don't use the flag from ":legacy" here.
+    cmdmod.cmod_flags &= ~CMOD_LEGACY;
+
     // Make sure error messages are OK.
     do_estack_push = !estack_top_is_ufunc(ufunc, 1);
     if (do_estack_push)
@@ -9403,6 +9407,7 @@ erret:
 
     current_sctx = save_current_sctx;
     estack_compiling = save_estack_compiling;
+    cmdmod.cmod_flags =        save_cmod_flags;
     if (do_estack_push)
        estack_pop();