diff options
author | Peter Stephenson <p.stephenson@samsung.com> | 2023-02-02 10:09:21 +0000 |
---|---|---|
committer | Peter Stephenson <p.stephenson@samsung.com> | 2023-02-02 10:09:21 +0000 |
commit | 21baad1037c1aa85384a81dd77a4661676336133 (patch) | |
tree | 1b7dfbabb4e5c5b17a347f5137d1bf11b07ab14c | |
parent | c8c894f83fbb07b4f65b2ac8db639680062b25d9 (diff) | |
download | zsh-21baad1037c1aa85384a81dd77a4661676336133.tar.gz zsh-21baad1037c1aa85384a81dd77a4661676336133.tar.xz zsh-21baad1037c1aa85384a81dd77a4661676336133.zip |
51307: Improve error on attempt to define function from aliased name
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | Src/input.c | 5 | ||||
-rw-r--r-- | Src/parse.c | 3 | ||||
-rw-r--r-- | Test/A02alias.ztst | 7 |
4 files changed, 18 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog index 05c7d86c7..ee9a623d4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2023-02-02 Peter Stephenson <p.stephenson@samsung.com> + + * 51307: Src/input.c, Src/parse.c, Test/A02alias.ztst: error + on attempt to expand alias in function definition name didn't + find the original alias and printed an extra error. + 2023-01-31 Bart Schaefer <schaefer@zsh.org> * 51342: Etc/zsh-development-guide: update PARAMDEF description diff --git a/Src/input.c b/Src/input.c index 5a612669b..0da065e51 100644 --- a/Src/input.c +++ b/Src/input.c @@ -816,6 +816,7 @@ char *input_hasalias(void) { int flags = inbufflags; struct instacks *instackptr = instacktop; + char *alias_nam = NULL; for (;;) { @@ -824,9 +825,9 @@ char *input_hasalias(void) DPUTS(instackptr == instack, "BUG: continuation at bottom of instack"); instackptr--; if (instackptr->alias) - return instackptr->alias->node.nam; + alias_nam = instackptr->alias->node.nam; flags = instackptr->flags; } - return NULL; + return alias_nam; } diff --git a/Src/parse.c b/Src/parse.c index 283225b74..a07a6cc71 100644 --- a/Src/parse.c +++ b/Src/parse.c @@ -2055,6 +2055,9 @@ par_simple(int *cmplx, int nr) if (isset(EXECOPT) && hasalias && !isset(ALIASFUNCDEF) && argc && hasalias != input_hasalias()) { zwarn("defining function based on alias `%s'", hasalias); + herrflush(); + if (noerrs != 2) + errflag |= ERRFLAG_ERROR; YYERROR(oecused); } diff --git a/Test/A02alias.ztst b/Test/A02alias.ztst index ca415fa39..1c6969e74 100644 --- a/Test/A02alias.ztst +++ b/Test/A02alias.ztst @@ -123,7 +123,12 @@ eval 'badalias() { print does not work; }') 1:ALIAS_FUNC_DEF off by default. ?(eval):1: defining function based on alias `badalias' -?(eval):1: parse error near `()' + + (alias firstalias=notacommand + alias secondalias=firstalias + eval 'secondalias() { print does not work either; }') +1:ALIAS_FUNC_DEF reports original alias if multiple +?(eval):1: defining function based on alias `secondalias' (alias goodalias=isafunc setopt ALIAS_FUNC_DEF |