about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2007-06-12 15:43:16 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2007-06-12 15:43:16 +0000
commit709aee90ce3b082fdb16b987ebf515e259a5e153 (patch)
tree23e7760496d827adba8a4039b780b8887707eebe
parent1a959dae01bca3b6e607dc15dda7e9f0c40078c0 (diff)
downloadzsh-709aee90ce3b082fdb16b987ebf515e259a5e153.tar.gz
zsh-709aee90ce3b082fdb16b987ebf515e259a5e153.tar.xz
zsh-709aee90ce3b082fdb16b987ebf515e259a5e153.zip
23553: unsubscripted array inside math eval behaves more rationally
-rw-r--r--ChangeLog4
-rw-r--r--Src/params.c20
2 files changed, 22 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 95cc20942..faafa6e98 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2007-06-12  Peter Stephenson  <pws@csr.com>
 
+	* 23553: Src/params.c: use of unsubscripted array inside
+	math evaluation now does something reasonable instead of
+	returning 0.
+
 	* 23552: Src/Builtins/sched.c: remove unnecessary debugging
 	warning.
 
diff --git a/Src/params.c b/Src/params.c
index 128d28e75..a44f21402 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -1941,10 +1941,18 @@ getarrvalue(Value v)
 mod_export zlong
 getintvalue(Value v)
 {
-    if (!v || v->isarr)
+    if (!v)
 	return 0;
     if (v->inv)
 	return v->start;
+    if (v->isarr) {
+	char **arr = getarrvalue(v);
+	if (arr) {
+	    char *scal = sepjoin(arr, NULL, 1);
+	    return mathevali(scal);
+	} else
+	    return 0;
+    }
     if (PM_TYPE(v->pm->node.flags) == PM_INTEGER)
 	return v->pm->gsu.i->getfn(v->pm);
     if (v->pm->node.flags & (PM_EFLOAT|PM_FFLOAT))
@@ -1959,10 +1967,18 @@ getnumvalue(Value v)
     mnumber mn;
     mn.type = MN_INTEGER;
 
-    if (!v || v->isarr) {
+
+    if (!v) {
 	mn.u.l = 0;
     } else if (v->inv) {
 	mn.u.l = v->start;
+    } else if (v->isarr) {
+	char **arr = getarrvalue(v);
+	if (arr) {
+	    char *scal = sepjoin(arr, NULL, 1);
+	    return matheval(scal);
+	} else
+	    mn.u.l = 0;
     } else if (PM_TYPE(v->pm->node.flags) == PM_INTEGER) {
 	mn.u.l = v->pm->gsu.i->getfn(v->pm);
     } else if (v->pm->node.flags & (PM_EFLOAT|PM_FFLOAT)) {