diff src/vim9compile.c @ 24408:96e0b898d5b4 v8.2.2744

patch 8.2.2744: Vim9: no way to explicitly ignore an argument Commit: https://github.com/vim/vim/commit/962c43bf0d6a33b905f2acd920d3701476ebb5c9 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Apr 10 17:18:09 2021 +0200 patch 8.2.2744: Vim9: no way to explicitly ignore an argument Problem: Vim9: no way to explicitly ignore an argument. Solution: Use the underscore as the name for an ignored argument.
author Bram Moolenaar <Bram@vim.org>
date Sat, 10 Apr 2021 17:30:03 +0200
parents a26f0fa12845
children e0fa539a9b34
line wrap: on
line diff
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -4416,6 +4416,12 @@ compile_expr7(
 
 	// "name" or "name()"
 	p = to_name_end(*arg, TRUE);
+	if (p - *arg == (size_t)1 && **arg == '_')
+	{
+	    emsg(_(e_cannot_use_underscore_here));
+	    return FAIL;
+	}
+
 	if (*p == '(')
 	{
 	    r = compile_call(arg, p - *arg, cctx, ppconst, 0);
@@ -6378,6 +6384,11 @@ compile_assignment(char_u *arg, exarg_T 
 	    semsg(_(e_cannot_assign_to_constant), lhs.lhs_name);
 	    goto theend;
 	}
+	if (is_decl && lhs.lhs_name[0] == '_' && lhs.lhs_name[1] == NUL)
+	{
+	    emsg(_(e_cannot_use_underscore_here));
+	    goto theend;
+	}
 
 	if (!heredoc)
 	{