patch 8.2.3720: Vim9: Internal error when invoking closure in legacy context
Problem: Vim9: Internal error when invoking closure in legacy context.
Solution: Give a more appropriate error message. (closes #9251)
diff --git a/src/vim9execute.c b/src/vim9execute.c
index 4b2763b..bd7f71e 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -2733,7 +2733,13 @@
if (outer == NULL)
{
SOURCING_LNUM = iptr->isn_lnum;
- iemsg("LOADOUTER depth more than scope levels");
+ if (ectx->ec_frame_idx == ectx->ec_initial_frame_idx
+ || ectx->ec_outer_ref == NULL)
+ // Possibly :def function called from legacy
+ // context.
+ emsg(_(e_closure_called_from_invalid_context));
+ else
+ iemsg("LOADOUTER depth more than scope levels");
goto theend;
}
tv = ((typval_T *)outer->out_stack->ga_data)