[GHC] #9915: GHCi has trouble with 'foreign' when it is not a keyword

#9915: GHCi has trouble with 'foreign' when it is not a keyword -------------------------------------+------------------------------------- Reporter: cactus | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Parser) | Version: 7.8.3 Keywords: GHCi | Operating System: Architecture: Unknown/Multiple | Unknown/Multiple Difficulty: Unknown | Type of failure: Blocked By: | None/Unknown Related Tickets: | Test Case: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- In Haskell 98 mode, `foreign` is not a keyword at all. The following is an example of a valid Haskell 98 program: {{{#!hs {-# LANGUAGE Haskell98 #-} module F where foreign :: Int foreign = 42 }}} However, it seems noone told GHCi about this: {{{ 12:42:38 [cactus@galaxy hs]$ ghci -XHaskell98 GHCi, version 7.8.3: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. λ» x = 42 -- Expected to fail <interactive>:2:3: parse error on input ‘=’ λ» x -- Expected to fail <interactive>:3:1: Not in scope: ‘x’ λ» -- So this should fail as well, right? λ» foreign = 42 λ» -- Nope λ» foreign 42 λ» -- But wait, there's more! λ» foreign -- boo! <interactive>:9:1: Parse error: naked expression at top level Perhaps you intended to use TemplateHaskell }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9915 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9915: GHCi has trouble with 'foreign' when it is not a keyword -------------------------------------+------------------------------------- Reporter: cactus | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.3 (Parser) | Keywords: GHCi Resolution: | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: Type of failure: | Related Tickets: None/Unknown | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by cactus): Of course, this is because `InteractiveUI.runStmt` decides to evaluate lines as declarations instead of statements based on a check vs. some hardcoded prefixes: {{{#!hs -- | Entry point to execute some haskell code from user runStmt :: String -> SingleStep -> GHCi Bool runStmt stmt step -- empty | null (filter (not.isSpace) stmt) = return False -- import | "import " `isPrefixOf` stmt = do addImportToContext stmt; return False -- data, class, newtype... | any (flip isPrefixOf stmt) declPrefixes = ... -- parse and run as Decl | otherwise = ... -- parse and run as Stmt -- | If we one of these strings prefixes a command, then we treat it as a decl -- rather than a stmt. declPrefixes :: [String] declPrefixes = ["class ","data ","newtype ","type ","instance ", "deriving ", "foreign ", "default ", "default("] }}} This gives a wrong result when `foreign` is not a keyword (and thus, a prefix of `foreign ` doesn't signify a declaration, like in the `foreign -- boo!` line in my original ticket). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9915#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9915: GHCi has trouble with 'foreign' when it is not a keyword -------------------------------------+------------------------------------- Reporter: cactus | Owner: cactus Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.3 (Parser) | Keywords: GHCi Resolution: | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: Type of failure: | Related Tickets: None/Unknown | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by cactus): * owner: => cactus -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9915#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9915: GHCi has trouble with 'foreign' when it is not a keyword
-------------------------------------+-------------------------------------
Reporter: cactus | Owner: cactus
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.8.3
(Parser) | Keywords: GHCi
Resolution: | Architecture: Unknown/Multiple
Operating System: | Difficulty: Unknown
Unknown/Multiple | Blocked By:
Type of failure: | Related Tickets:
None/Unknown |
Test Case: |
Blocking: |
Differential Revisions: |
-------------------------------------+-------------------------------------
Comment (by Dr. ERDI Gergo

#9915: GHCi has trouble with 'foreign' when it is not a keyword -------------------------------------+------------------------------------- Reporter: cactus | Owner: cactus Type: bug | Status: merge Priority: normal | Milestone: 7.8.4 Component: Compiler | Version: 7.8.3 (Parser) | Keywords: GHCi Resolution: | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: Type of failure: | Related Tickets: None/Unknown | Test Case: | ghci/should_compile/T9915 | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by cactus): * status: new => merge * testcase: => ghci/should_compile/T9915 * milestone: => 7.8.4 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9915#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9915: GHCi has trouble with 'foreign' when it is not a keyword -------------------------------------+------------------------------------- Reporter: cactus | Owner: cactus Type: bug | Status: closed Priority: normal | Milestone: 7.10.1 Component: Compiler | Version: 7.8.3 (Parser) | Keywords: GHCi Resolution: fixed | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: Type of failure: | Related Tickets: None/Unknown | Test Case: | ghci/should_compile/T9915 | Blocking: 9900 | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by thoughtpolice): * status: merge => closed * resolution: => fixed * milestone: 7.8.4 => 7.10.1 Comment: 7.8.4 is already done; closing. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9915#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC