
#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