Ticket #1215 (closed bug: fixed)

Opened 2 years ago

Last modified 9 months ago

GHC fails to respect the maximal munch rule while lexing "qualified reservedids"

Reported by: Stefan O'Rear <stefanor@cox.net> Assigned to: simonmar
Priority: low Milestone: 6.8.1
Component: Compiler (Parser) Version: 6.6
Severity: normal Keywords:
Cc: Difficulty: Easy (1 hr)
Test Case: Operating System: Unknown/Multiple
Architecture: Unknown/Multiple

Description

The following program I believe is legal haskell 98:

module Main where

t = 2
defaul _ = return ()
main = Main.default

since Main.default is an illegal lexeme, but Main.defaul is a perfectly good qvarid. however ghci rejects it:

Bar.hs:5:12: parse error on input `default'

Something very similar to this is documented, but only in the qvarsym case. This appears fairly easy to fix using extra rules in the lexer; a flex lexer that does what I consider correct can be found at http://members.cox.net/stefanor/h98lexer.l.

Change History

03/12/07 06:26:29 changed by igloo

Technically you are right, but I think it would be better to just say in Haskell' that Main.default should not be parsed as Main.defaul t. Any objections before I close the bug?

03/13/07 08:12:32 changed by simonmar

  • owner set to simonmar.
  • difficulty changed from Unknown to Easy (1 hr).
  • milestone set to 6.8.

Interesting. It turns out I misinterpreted the Haskell lexical syntax: GHC lexes M.default as M . default, because M.default is not a valid qvarid but I neglected to take into account the maximal munch rule.

We have an open ticket for Haskell' about this: http://hackage.haskell.org/cgi-bin/haskell-prime/trac.cgi/wiki/QualifiedIdentifiers, which was until just now inaccurate (I've now fixed it). I propose to fix GHC in 6.8 to match the Haskell' proposal.

07/24/07 06:55:34 changed by simonmar

  • status changed from new to closed.
  • resolution set to fixed.

Fixed:

Tue Jul 24 14:04:17 BST 2007  Simon Marlow <simonmar@microsoft.com>
  * FIX #1215: GHC fails to respect the maximal munch rule while lexing "qualified reservedids"

  I didn't actually fix this to respect Haskell 98, instead I changed it
  to follow the proposal for Haskell':
  
  http://hackage.haskell.org/cgi-bin/haskell-prime/trac.cgi/wiki/QualifiedIdentifiers
  
  Rationale:
  
    - We didn't respect Haskell 98 with respect to qualified symbols either
    - The Haskell' change makes things much cleaner
    - Obeying the Haskell 98 spec literally has some unintended
      consequences (e.g. M.where must lex as "M.wher" "e")
    - Any programs that compiled before this change and do not compile
      after it were illegal according to Haskell 98 anyway.

11/05/07 07:04:01 changed by igloo

  • milestone changed from 6.8 branch to 6.8.1.

09/30/08 08:40:48 changed by simonmar

  • architecture changed from Unknown to Unknown/Multiple.

09/30/08 08:52:06 changed by simonmar

  • os changed from Unknown to Unknown/Multiple.