about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2002-10-29 10:56:38 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2002-10-29 10:56:38 +0000
commitff23ebe925752236ecf28318feee0a7f40e34e8e (patch)
tree9514c4f5724a652254f2e8a204c465c3c6cbea84
parent7bfc0f1b5c3f4f02193d7b5e1d631b224e054f8b (diff)
downloadzsh-ff23ebe925752236ecf28318feee0a7f40e34e8e.tar.gz
zsh-ff23ebe925752236ecf28318feee0a7f40e34e8e.tar.xz
zsh-ff23ebe925752236ecf28318feee0a7f40e34e8e.zip
17872: Fix `typeset SECONDS' when creating local parameter
-rw-r--r--ChangeLog3
-rw-r--r--Src/builtin.c25
2 files changed, 25 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 610b0c88e..0e88e9a0d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2002-10-29  Peter Stephenson  <pws@csr.com>
 
+	* 17872: Src/builtin.c: Make sure `typeset SECONDS' uses a
+	suitable type when creating a new local parameter.
+
 	* 17868: Src/builtin.c, Src/params.c, Doc/Zsh/params.yo:
 	Can `typeset -F SECONDS' to get better accuracy.  Try to
 	catch all cases when converting or creating local copy
diff --git a/Src/builtin.c b/Src/builtin.c
index 9f1c2dcb6..045c80f36 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -1732,11 +1732,30 @@ typeset_single(char *cname, char *pname, Param pm, int func,
 	    int err = 1;
 	    if (!readonly && !strcmp(pname, "SECONDS"))
 	    {
+		/*
+		 * We allow SECONDS to change type between integer
+		 * and floating point.  If we are creating a new
+		 * local copy we check the type here and allow
+		 * a new special to be created with that type.
+		 * We then need to make sure the correct type
+		 * for the special is restored at the end of the scope.
+		 * If we are changing the type of an existing
+		 * parameter, we do the whole thing here.
+		 */
 		if (newspecial != NS_NONE)
 		{
-		    newspecial = NS_SECONDS;
-		    err = 0;	/* and continue */
-		    tc = 0;	/* but don't do a normal conversion */
+		    /*
+		     * The first test allows `typeset' to copy the
+		     * existing type.  This is the usual behaviour
+		     * for making special parameters local.
+		     */
+		    if (PM_TYPE(on) == 0 || PM_TYPE(on) == PM_INTEGER ||
+			PM_TYPE(on) == PM_FFLOAT || PM_TYPE(on) == PM_EFLOAT)
+		    {
+			newspecial = NS_SECONDS;
+			err = 0;	/* and continue */
+			tc = 0;	/* but don't do a normal conversion */
+		    }
 		} else if (!setsecondstype(pm, on, off)) {
 		    if (value && !setsparam(pname, ztrdup(value)))
 			return NULL;