diff src/vim9compile.c @ 20055:686deb5959c2 v8.2.0583

patch 8.2.0583: Vim9: # comment not recognized in :def function Commit: https://github.com/vim/vim/commit/cb711abf0f71d8c743cf73c76077f52e17732a8c Author: Bram Moolenaar <Bram@vim.org> Date: Thu Apr 16 13:00:29 2020 +0200 patch 8.2.0583: Vim9: # comment not recognized in :def function Problem: Vim9: # comment not recognized in :def function. Solution: Recognize and skip # comment.
author Bram Moolenaar <Bram@vim.org>
date Thu, 16 Apr 2020 13:15:05 +0200
parents 04ef2ccf2519
children de756b3f4dee
line wrap: on
line diff
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -5772,7 +5772,7 @@ compile_def_function(ufunc_T *ufunc, int
      */
     for (;;)
     {
-	int	is_ex_command;
+	int	is_ex_command = FALSE;
 
 	// Bail out on the first error to avoid a flood of errors and report
 	// the right line number when inside try/catch.
@@ -5791,6 +5791,7 @@ compile_def_function(ufunc_T *ufunc, int
 	{
 	    line = next_line_from_context(&cctx);
 	    if (cctx.ctx_lnum >= ufunc->uf_lines.ga_len)
+		// beyond the last line
 		break;
 	}
 	emsg_before = called_emsg;
@@ -5800,36 +5801,54 @@ compile_def_function(ufunc_T *ufunc, int
 	ea.cmdlinep = &line;
 	ea.cmd = skipwhite(line);
 
-	// "}" ends a block scope
-	if (*ea.cmd == '}')
+	// Some things can be recognized by the first character.
+	switch (*ea.cmd)
 	{
-	    scopetype_T stype = cctx.ctx_scope == NULL
-					 ? NO_SCOPE : cctx.ctx_scope->se_type;
-
-	    if (stype == BLOCK_SCOPE)
-	    {
-		compile_endblock(&cctx);
-		line = ea.cmd;
-	    }
-	    else
-	    {
-		emsg(_("E1025: using } outside of a block scope"));
-		goto erret;
-	    }
-	    if (line != NULL)
-		line = skipwhite(ea.cmd + 1);
-	    continue;
+	    case '#':
+		// "#" starts a comment, but not "#{".
+		if (ea.cmd[1] != '{')
+		{
+		    line = (char_u *)"";
+		    continue;
+		}
+		break;
+
+	    case '}':
+		{
+		    // "}" ends a block scope
+		    scopetype_T stype = cctx.ctx_scope == NULL
+					  ? NO_SCOPE : cctx.ctx_scope->se_type;
+
+		    if (stype == BLOCK_SCOPE)
+		    {
+			compile_endblock(&cctx);
+			line = ea.cmd;
+		    }
+		    else
+		    {
+			emsg(_("E1025: using } outside of a block scope"));
+			goto erret;
+		    }
+		    if (line != NULL)
+			line = skipwhite(ea.cmd + 1);
+		    continue;
+		}
+
+	    case '{':
+		// "{" starts a block scope
+		// "{'a': 1}->func() is something else
+		if (ends_excmd(*skipwhite(ea.cmd + 1)))
+		{
+		    line = compile_block(ea.cmd, &cctx);
+		    continue;
+		}
+		break;
+
+	    case ':':
+		is_ex_command = TRUE;
+		break;
 	}
 
-	// "{" starts a block scope
-	// "{'a': 1}->func() is something else
-	if (*ea.cmd == '{' && ends_excmd(*skipwhite(ea.cmd + 1)))
-	{
-	    line = compile_block(ea.cmd, &cctx);
-	    continue;
-	}
-	is_ex_command = *ea.cmd == ':';
-
 	/*
 	 * COMMAND MODIFIERS
 	 */