v9.CheckScriptFailureList(lines, ["E1356:", "E1405:"])
enddef
+def Test_skipped_lambda_after_else()
+ var lines =<< trim END
+ vim9script
+ def g:Warn(msg: string)
+ if has('patch-9.0.0321')
+ echo msg
+ else
+ timer_start(100, (_) => {
+ echohl WarningMsg | echom msg | echohl None
+ }, {repeat: 0})
+ endif
+ enddef
+ defcompile
+ END
+ v9.CheckScriptSuccess(lines)
+ delfunc! g:Warn
+enddef
+
def s:check_previewpopup(expected_title: string)
var id = popup_findpreview()
assert_notequal(id, 0)
return generate_NEWTUPLE(cctx, count, FALSE);
}
+/*
+ * Restore "*arg" from a temporary cmdline copy.
+ */
+ static void
+restore_cmdline_arg(evalarg_T *evalarg, char_u **arg, cctx_T *cctx)
+{
+ garray_T *gap;
+ char_u *line;
+ size_t off;
+
+ if (!evalarg->eval_using_cmdline || cctx == NULL)
+ return;
+
+ gap = &evalarg->eval_tofree_ga;
+ if (gap->ga_len == 0)
+ return;
+
+ off = *arg - ((char_u **)gap->ga_data)[gap->ga_len - 1];
+ line = ((char_u **)cctx->ctx_ufunc->uf_lines.ga_data)[cctx->ctx_lnum];
+ *arg = line + off;
+ evalarg->eval_using_cmdline = FALSE;
+}
+
/*
* Parse a lambda: "(arg, arg) => expr"
* "*arg" points to the '('.
compile_def_function(ufunc, FALSE, compile_type, cctx);
}
- // The last entry in evalarg.eval_tofree_ga is a copy of the last line and
- // "*arg" may point into it. Point into the original line to avoid a
- // dangling pointer.
- if (evalarg.eval_using_cmdline)
- {
- garray_T *gap = &evalarg.eval_tofree_ga;
- size_t off = *arg - ((char_u **)gap->ga_data)[gap->ga_len - 1];
-
- *arg = ((char_u **)cctx->ctx_ufunc->uf_lines.ga_data)[cctx->ctx_lnum]
- + off;
- evalarg.eval_using_cmdline = FALSE;
- }
+ restore_cmdline_arg(&evalarg, arg, cctx);
clear_evalarg(&evalarg, NULL);
init_evalarg(&evalarg);
evalarg.eval_cctx = cctx;
skip_expr(arg, &evalarg);
+ restore_cmdline_arg(&evalarg, arg, cctx);
clear_evalarg(&evalarg, NULL);
}