]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.3187: Vim9: popup timer callback is not compiled v8.2.3187
authorBram Moolenaar <Bram@vim.org>
Mon, 19 Jul 2021 20:19:29 +0000 (22:19 +0200)
committerBram Moolenaar <Bram@vim.org>
Mon, 19 Jul 2021 20:19:29 +0000 (22:19 +0200)
Problem:    Vim9: popup timer callback is not compiled.
Solution:   Compile the callback when creating the timer.

src/popupwin.c
src/proto/vim9compile.pro
src/version.c
src/vim9compile.c

index 0f6166aca12424667aef43acee8d447e0c4be291..747852735d10e91469c7aa2e74e88a8cd8db9cf9 100644 (file)
@@ -383,8 +383,8 @@ popup_add_timeout(win_T *wp, int time)
     typval_T       tv;
 
     vim_snprintf((char *)cbbuf, sizeof(cbbuf),
-                                      "{_ -> popup_close(%d)}", wp->w_id);
-    if (get_lambda_tv(&ptr, &tv, FALSE, &EVALARG_EVALUATE) == OK)
+                                      "(_) => popup_close(%d)", wp->w_id);
+    if (get_lambda_tv_and_compile(&ptr, &tv, FALSE, &EVALARG_EVALUATE) == OK)
     {
        wp->w_popup_timer = create_timer(time, 0);
        wp->w_popup_timer->tr_callback = get_callback(&tv);
index 881dddc510bf244d6141231acfb7036f4a931725..bdefb4ec91f9e327fc1bfaa1e03b01855b25a03a 100644 (file)
@@ -11,6 +11,7 @@ char_u *peek_next_line_from_context(cctx_T *cctx);
 char_u *next_line_from_context(cctx_T *cctx, int skip_comment);
 char_u *to_name_end(char_u *arg, int use_namespace);
 char_u *to_name_const_end(char_u *arg);
+int get_lambda_tv_and_compile(char_u **arg, typval_T *rettv, int types_optional, evalarg_T *evalarg);
 exprtype_T get_compare_type(char_u *p, int *len, int *type_is);
 void error_white_both(char_u *op, int len);
 void fill_exarg_from_cctx(exarg_T *eap, cctx_T *cctx);
index 0710ce0614a56c0e7a46c1819870374152f40f8d..64997fd9ed210990e0d88601777c87427dd7a34b 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3187,
 /**/
     3186,
 /**/
index 12dd19823aa6db71b286a74e3aca2c537bed6737..97031ef283ab7f8658af0ca81ee4ce4c862edd24 100644 (file)
@@ -3670,6 +3670,47 @@ compile_lambda(char_u **arg, cctx_T *cctx)
     return FAIL;
 }
 
+/*
+ * Get a lambda and compile it.  Uses Vim9 syntax.
+ */
+    int
+get_lambda_tv_and_compile(
+       char_u      **arg,
+       typval_T    *rettv,
+       int         types_optional,
+       evalarg_T   *evalarg)
+{
+    int                r;
+    ufunc_T    *ufunc;
+    int                save_sc_version = current_sctx.sc_version;
+
+    // Get the funcref in "rettv".
+    current_sctx.sc_version = SCRIPT_VERSION_VIM9;
+    r = get_lambda_tv(arg, rettv, types_optional, evalarg);
+    current_sctx.sc_version = save_sc_version;
+    if (r != OK)
+       return r;
+
+    // "rettv" will now be a partial referencing the function.
+    ufunc = rettv->vval.v_partial->pt_func;
+
+    // Compile it here to get the return type.  The return type is optional,
+    // when it's missing use t_unknown.  This is recognized in
+    // compile_return().
+    if (ufunc->uf_ret_type == NULL || ufunc->uf_ret_type->tt_type == VAR_VOID)
+       ufunc->uf_ret_type = &t_unknown;
+    compile_def_function(ufunc, FALSE, CT_NONE, NULL);
+
+    if (ufunc->uf_def_status == UF_COMPILED)
+    {
+       // The return type will now be known.
+       set_function_type(ufunc);
+       return OK;
+    }
+    clear_tv(rettv);
+    return FAIL;
+}
+
 /*
  * parse a dict: {key: val, [key]: val}
  * "*arg" points to the '{'.