diff src/vim9compile.c @ 22973:4c97c0747017 v8.2.2033

patch 8.2.2033: Vim9: :def without argument gives compilation error Commit: https://github.com/vim/vim/commit/6abdcf82859e158713a3d5aa6b1012748ea5c2a0 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Nov 22 18:15:44 2020 +0100 patch 8.2.2033: Vim9: :def without argument gives compilation error Problem: Vim9: :def without argument gives compilation error. Solution: Add the DEF instruction. (closes https://github.com/vim/vim/issues/7344)
author Bram Moolenaar <Bram@vim.org>
date Sun, 22 Nov 2020 18:30:05 +0100
parents d3b26055bfa8
children a943b175586a
line wrap: on
line diff
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -1433,6 +1433,26 @@ generate_NEWFUNC(cctx_T *cctx, char_u *l
 }
 
 /*
+ * Generate an ISN_DEF instruction: list functions
+ */
+    static int
+generate_DEF(cctx_T *cctx, char_u *name, size_t len)
+{
+    isn_T	*isn;
+
+    RETURN_OK_IF_SKIP(cctx);
+    if ((isn = generate_instr(cctx, ISN_DEF)) == NULL)
+	return FAIL;
+    if (len > 0)
+    {
+	isn->isn_arg.string = vim_strnsave(name, len);
+	if (isn->isn_arg.string == NULL)
+	    return FAIL;
+    }
+    return OK;
+}
+
+/*
  * Generate an ISN_JUMP instruction.
  */
     static int
@@ -4801,6 +4821,27 @@ compile_nested_function(exarg_T *eap, cc
 	return NULL;
     }
 
+    if (*name_start == '/')
+    {
+	name_end = skip_regexp(name_start + 1, '/', TRUE);
+	if (*name_end == '/')
+	    ++name_end;
+	eap->nextcmd = check_nextcmd(name_end);
+    }
+    if (name_end == name_start || *skipwhite(name_end) != '(')
+    {
+	if (!ends_excmd2(name_start, name_end))
+	{
+	    semsg(_(e_invalid_command_str), eap->cmd);
+	    return NULL;
+	}
+
+	// "def" or "def Name": list functions
+	if (generate_DEF(cctx, name_start, name_end - name_start) == FAIL)
+	    return NULL;
+	return eap->nextcmd == NULL ? (char_u *)"" : eap->nextcmd;
+    }
+
     // Only g:Func() can use a namespace.
     if (name_start[1] == ':' && !is_global)
     {
@@ -7736,22 +7777,23 @@ delete_instr(isn_T *isn)
 {
     switch (isn->isn_type)
     {
+	case ISN_DEF:
 	case ISN_EXEC:
+	case ISN_LOADB:
 	case ISN_LOADENV:
 	case ISN_LOADG:
-	case ISN_LOADB:
-	case ISN_LOADW:
+	case ISN_LOADOPT:
 	case ISN_LOADT:
-	case ISN_LOADOPT:
-	case ISN_STRINGMEMBER:
+	case ISN_LOADW:
 	case ISN_PUSHEXC:
+	case ISN_PUSHFUNC:
 	case ISN_PUSHS:
+	case ISN_STOREB:
 	case ISN_STOREENV:
 	case ISN_STOREG:
-	case ISN_STOREB:
+	case ISN_STORET:
 	case ISN_STOREW:
-	case ISN_STORET:
-	case ISN_PUSHFUNC:
+	case ISN_STRINGMEMBER:
 	    vim_free(isn->isn_arg.string);
 	    break;