zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: Inconsistency of GLOB_ASSIGN
Date: Thu, 27 Nov 2014 15:00:36 -0800	[thread overview]
Message-ID: <141127150036.ZM5089@torch.brasslantern.com> (raw)
In-Reply-To: <141127133833.ZM6853@torch.brasslantern.com>

NOTE:  The two patches included in this message are mutually exclusive.
Do not attempt to apply both of them on top of one another.

On Nov 27,  1:38pm, Bart Schaefer wrote:
}
} On Nov 27,  8:43pm, Peter Stephenson wrote:
} }
} } It would be neater always to do an array assignment, in fact, but
} } the traditional behaviour is that if there was only one result the
} } assignment is scalar
} 
} That's too bad, because making it always be an array assignment is a
} lot simpler than figuring out whether the glob expanded to something.

So in actuality, not too much different.  Below are two patches, pick
one ... both need the haswilds() test to preserve the behavior of
assigning a non-glob-string-that-looks-like-math to an integer/float.

Here is the patch for making the assigment always be an array:

--- 8< --- snip --- 8< ---
diff --git a/Src/exec.c b/Src/exec.c
index 02a8fe3..702b731 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -2243,8 +2243,11 @@ addvars(Estate state, Wordcode pc, int addflags)
 		state->pc = opc;
 		return;
 	    }
-	    if (isset(GLOBASSIGN) || !isstr)
+	    if (!isstr || (isset(GLOBASSIGN) &&
+			   haswilds((char *)getdata(firstnode(vl))))) {
 		globlist(vl, 0);
+		isstr = 0;
+	    }
 	    if (errflag) {
 		state->pc = opc;
 		return;
--- >8 --- snip --- >8 ---

And here is the patch for making the type scalar or array based on how
many results got returned:

--- 8< --- snip --- 8< ---
diff --git a/Src/exec.c b/Src/exec.c
index 02a8fe3..2b7c55f 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -2243,8 +2243,16 @@ addvars(Estate state, Wordcode pc, int addflags)
 		state->pc = opc;
 		return;
 	    }
-	    if (isset(GLOBASSIGN) || !isstr)
+	    if (!isstr || (isset(GLOBASSIGN) &&
+			   haswilds((char *)getdata(firstnode(vl))))) {
 		globlist(vl, 0);
+		/* Unset the parameter to force it to be recreated
+		 * as either scalar or array depending on how many
+		 * matches were found for the glob.
+		 */
+		if (isset(GLOBASSIGN))
+		    unsetparam(name);
+	    }
 	    if (errflag) {
 		state->pc = opc;
 		return;
--- >8 --- snip --- >8 ---


All tests (except X02zlevi some of the time) still pass with either of
the above, but there may be hidden consequences of each.


  reply	other threads:[~2014-11-27 23:01 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-27  5:57 Bart Schaefer
2014-11-27 20:43 ` Peter Stephenson
2014-11-27 20:51   ` Bart Schaefer
2014-11-27 21:38   ` Bart Schaefer
2014-11-27 23:00     ` Bart Schaefer [this message]
2014-11-28  9:34       ` Peter Stephenson
2014-11-28 18:39         ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=141127150036.ZM5089@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).