Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: zcalc bug



Matthias Kopfermann wrote:
> i saw a sweet output when doing
> 
> print $((3*4,))
> 
> BUG: math: not enough wallabies in outback.

Fair dinkum blue (sorry, Geoff)...

The comment above it says
	/* Make sure anyone seeing this message reports it. */
so this worked.

The real bug is that it continues the calculation and outputs 12,
without reporting a user error.

I think this is the fix.  The precedence of comma was the highest
precedence, which incorrectly indicated it didn't need an argument.
It simply(?) needs to be at an intervening precedence, without
disturbing the other ordering.

Index: Src/math.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/math.c,v
retrieving revision 1.19
diff -u -r1.19 math.c
--- Src/math.c	11 Aug 2003 10:45:10 -0000	1.19
+++ Src/math.c	13 May 2004 19:59:42 -0000
@@ -168,8 +168,8 @@
      0,  16, 0
 };
 
-#define TOPPREC 17
-#define ARGPREC (TOPPREC-1)
+#define TOPPREC 18
+#define ARGPREC 16
 
 static int type[TOKCOUNT] =
 {
Index: Test/C01arith.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/C01arith.ztst,v
retrieving revision 1.7
diff -u -r1.7 C01arith.ztst
--- Test/C01arith.ztst	17 Dec 2003 20:47:40 -0000	1.7
+++ Test/C01arith.ztst	13 May 2004 19:59:42 -0000
@@ -110,3 +110,23 @@
   print $(( ))
 0:empty math parse e.g. $(( )) acts like a zero
 >0
+
+  print $(( a = ))
+1:empty assignment
+?(eval):1: bad math expression: operand expected at `'
+
+  print $(( 3, ))
+1:empty right hand of comma
+?(eval):1: bad math expression: operand expected at `'
+
+  print $(( 3,,4 ))
+1:empty middle of comma
+?(eval):1: bad math expression: operand expected at `,4 '
+
+  print $(( (3 + 7, 4), 5 ))
+0:commas and parentheses, part 1
+>5
+
+  print $(( 5, (3 + 7, 4) ))
+0:commas and parentheses, part 1
+>4

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxxxxxxxxx>
Work: pws@xxxxxxx
Web: http://www.pwstephenson.fsnet.co.uk



Messages sorted by: Reverse Date, Date, Thread, Author