Opened 11 years ago

Closed 11 years ago

Last modified 8 years ago

#870 closed bug (fixed)

extra commas accepted in import export lists

Reported by: ross Owned by:
Priority: normal Milestone:
Component: Compiler (Parser) Version: 6.4.2
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


GHC accepts non-standard imports like

import M (,,foo,,,bar,,,)

creating problems for other Haskell implementations. Ditto for exports.

Suggest modifying this part of the grammar:

exportlist :: { [LIE RdrName] }
        :  exportlist ',' export                { $3 : $1 }
        |  exportlist ','                       { $1 }
        |  export                               { [$1]  }
        |  {- empty -}                          { [] }


exportlist :: { [LIE RdrName] }
        :  exportlist1 ','                      { $1 }
        |  exportlist1                          { $1 }
        |  {- empty -}                          { [] }
exportlist1 :: { [LIE RdrName] }
        :  exportlist1 ',' export               { $3 : $1 }
        |  export                               { [$1]  }

Change History (6)

comment:1 Changed 11 years ago by duncan

Though of course, existing programs use this and will break. I'm not saying don't do it, just bear that in mind.

I'll have to go change every module in Gtk2Hs. :-)

One advantage of allowing extra ','s is that it makes it easier to see what's really changed in a diff and it makes using #ifdefs in export lists easier.

If this is going to change perhaps start by deprecating them and making it a warning so people will have a chance to fix their code.

comment:2 Changed 11 years ago by ross

Component: CompilerCompiler (Parser)

Just to be clear, this patch implements the Haskell 98 syntax:

exports 	 -> 	 ( export1 , ... , exportn [ , ] ) 	 (n>=0)

i.e. it allows an optional extra comma at the end, but not at the start or next to another comma.

comment:3 Changed 11 years ago by duncan

Yes, I misunderstood. I make use of the extra comma at the end but not lots in the middle. So I have no objection to the change.

comment:4 Changed 11 years ago by simonmar

Resolution: fixed
Status: newclosed

Fixed, though not exactly as per Ross's suggestion, but that's mainly because I hadn't noticed this bug report at the time I fixed it.

comment:5 Changed 8 years ago by simonmar

Architecture: UnknownUnknown/Multiple

comment:6 Changed 8 years ago by simonmar

Operating System: UnknownUnknown/Multiple
Note: See TracTickets for help on using tickets.