zsh-workers
 help / color / mirror / code / Atom feed
* Possibly unexpected difference between builtin and reserved typeset
@ 2016-09-15  9:29 Mikael Magnusson
  2016-09-18 20:41 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Mikael Magnusson @ 2016-09-15  9:29 UTC (permalink / raw)
  To: zsh workers

% foo=bar \typeset foo; echo . $foo .
foo=bar
. .
% foo=bar typeset foo; echo . $foo .
foo=bar
. bar .

Out of the ones I tried in $reswords, typeset and friends seem to be
the only ones that aren't a syntax error after parameter assignments,
so I guess that might be why the code doesn't handle it?

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Possibly unexpected difference between builtin and reserved typeset
  2016-09-15  9:29 Possibly unexpected difference between builtin and reserved typeset Mikael Magnusson
@ 2016-09-18 20:41 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2016-09-18 20:41 UTC (permalink / raw)
  To: zsh workers

On Sep 15, 11:29am, Mikael Magnusson wrote:
} Subject: Possibly unexpected difference between builtin and reserved types
}
} % foo=bar \typeset foo; echo . $foo .
} foo=bar
} . .
} % foo=bar typeset foo; echo . $foo .
} foo=bar
} . bar .
} 
} Out of the ones I tried in $reswords, typeset and friends seem to be
} the only ones that aren't a syntax error after parameter assignments,
} so I guess that might be why the code doesn't handle it?

This is related to the "x=2 | ..." problem discussed in another thread,
but easier to fix.

I think the following does the right thing WRT POSIX_BUILTINS, but if
anyone would care to devise a test case, please do.

There's one potential strange edge case.  *Before* the patch below:

torch% foo=bar
torch% foo=fred \typeset foo=ding; echo . $foo .
. bar .
torch% foo=fred typeset foo=ding; echo . $foo . 
. ding .

*After* the patch:

torch% foo=bar
torch% foo=fred \typeset foo=ding; echo . $foo .
. bar .
torch% foo=fred typeset foo=ding; echo . $foo .
. bar .

I believe only the before+resword case is correct, that is, all four
should end up with "ding" assigned to $foo, and if that's true, it's
going to be pretty ugly to fix -- but it's possible that both after
cases are correct.


diff --git a/Src/exec.c b/Src/exec.c
index 9a7234e..d924148 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -3543,7 +3543,7 @@ execcmd(Estate state, int input, int output, int how, int last1)
 		     * if it's got "command" in front.
 		     * If it's a normal command --- save.
 		     */
-		    if (is_shfunc || (hn->flags & BINF_PSPECIAL))
+		    if (is_shfunc || (hn->flags & (BINF_PSPECIAL|BINF_ASSIGN)))
 			do_save = (orig_cflags & BINF_COMMAND);
 		    else
 			do_save = 1;
@@ -3552,7 +3552,7 @@ execcmd(Estate state, int input, int output, int how, int last1)
 		     * Save if it's got "command" in front or it's
 		     * not a magic-equals assignment.
 		     */
-		    if ((cflags & BINF_COMMAND) || !assign)
+		    if ((cflags & (BINF_COMMAND|BINF_ASSIGN)) || !assign)
 			do_save = 1;
 		}
 		if (do_save && varspc)


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-09-18 21:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-15  9:29 Possibly unexpected difference between builtin and reserved typeset Mikael Magnusson
2016-09-18 20:41 ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).