Malcolm Wallace wrote:
>
> Bug Report for Hugs98 (May 1999 version) compiled with readline
> support, if that is relevant.
>
> There is a bug in deriving instances of Show, illustrated here when
> the datatype has a constructor containing a \.
>
> For this code:
> data X = X
> | X :\ X
> deriving Show
> main = putStrLn (show (X :\ X))
>
> a call of "main" produces
> X :<nofile> X
> whilst a direct call to "show (X :\ X)" produces
> "X:\NUL<nofile> X"
> instead of the expected
> X :\ X
>
> If I extend the datatype with an extra constructor to
> data X = X
> | X :\ X
> | C X
> deriving Show
> main = putStrLn (show (X :\ X))
>
> then for the same two expressions I get respectively
> X :C X
> "X :\NULC X"
>
> Regards,
> Malcolm
Here's a new patch fixing the problem. Ignore the previous patch,
it caused more problems than it fixed :-)
Note the line numbers are for a local copy of Hugs, so might
be slightly different.
Hope this helps,
Andy
Index: static.c
===================================================================
RCS file: /home/cvs/root/hugs98/src/static.c,v
retrieving revision 1.6
diff -r1.6 static.c
3600c3622
< ap(nameApp,mkStr(name(h).text)),
---
> ap(nameApp,mkStr(fixLitText(name(h).text))),
3603c3625,3626
< rhs = ap2(nameComp,ap(nameApp,mkStr(name(h).text)),rhs);
---
> rhs = ap2(nameComp,
> ap(nameApp,mkStr(fixLitText(name(h).text))),rhs);
Index: storage.c
===================================================================
RCS file: /home/cvs/root/hugs98/src/storage.c,v
retrieving revision 1.2
diff -r1.2 storage.c
142a143,164
> #define MAX_FIXLIT 100
> Text fixLitText(t) /* fix literal text that might include \ */
> Text t; {
> String s = textToStr(t);
> char p[MAX_FIXLIT];
> Int i;
> for(i = 0;i < MAX_FIXLIT-2 && *s;s++) {
> p[i++] = *s;
> if (*s == '\\') {
> p[i++] = '\\';
> }
> }
> if (i < MAX_FIXLIT-2) {
> p[i] = 0;
> } else {
> ERRMSG(0) "storage space exhausted for internal literal string"
> EEND;
> }
> return (findText(p));
> }
> #undef MAX_FIXLIT
Index: storage.h
===================================================================
RCS file: /home/cvs/root/hugs98/src/storage.h,v
retrieving revision 1.4
diff -r1.4 storage.h
63a64
> extern Text fixLitText Args((Text));