[nhc-bugs] Misleading error message for underscore patterns

Malcolm Wallace Malcolm.Wallace at cs.york.ac.uk
Tue Jun 14 06:21:50 EDT 2005


Tony Sloane <asloane at ics.mq.edu.au> writes:

> Not really a bug, but a confusion from a misleading error message.   
> The following code contains underscore identifier patterns which are  
> accepted by nhc98 when the -98 option is given:
> 
> foo _2a = 1
> bar (T a _2b) = 1
> 
> (I don't have the H98 definition handy but I'm presuming that nhc is  
> correct in allowing these patterns in H98.)

Yes, these patterns are legal H'98.  It is wrong that nhc98 should complain
about them when the -underscore flag is off (the default, except with -98).

> However, when -98 is not present, errors are reported that are  
> misleading in that they refer to the "foo" and "bar" tokens, not the  
> bad patterns, and they don't complain about the patterns at all:
> 
> 3:1-3:3 Found foo but expected a {-end-of-definition-or-EOF-}
> 5:1-5:3 Found bar but expected a {-end-of-definition-or-EOF-}

Yes, the lexical error is being transformed into a parse error,
which is indeed confusing.  This is easily fixed though.  A patch is
attached, and will appear in CVS shortly.

Regards,
    Malcolm
-------------- next part --------------
Index: src/compiler98/LexLow.hs
===================================================================
RCS file: /home/cvs/root/nhc98/src/compiler98/LexLow.hs,v
retrieving revision 1.9
diff -u -r1.9 LexLow.hs
--- src/compiler98/LexLow.hs	30 Jun 2004 12:29:28 -0000	1.9
+++ src/compiler98/LexLow.hs	14 Jun 2005 10:20:45 -0000
@@ -98,7 +98,8 @@
   else if isLower x
   then  case splitWhile isNhcId [] xs of
 	(var,xs) -> LEX_VARID var 0 (length var) xs
-  else LEX_ERROR x xs
+--else LEX_ERROR x xs	-- maybe better to drop through to lowercase=True ?
+  else lexOne True xs
 
 lexOne True xs@('_':_) =
   case splitWhile isNhcId [] xs of


More information about the Nhc-bugs mailing list