[GHC] #8639: GHC API `runStmt` overrides qualified import of `it` variable

#8639: GHC API `runStmt` overrides qualified import of `it` variable ------------------------------------+------------------------------------- Reporter: agibiansky | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: GHC API | Version: 7.6.3 Keywords: | Operating System: Unknown/Multiple Architecture: Unknown/Multiple | Type of failure: None/Unknown Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | ------------------------------------+------------------------------------- The `runStmt` function in `InteractiveEval` creates an `it` variable storing the last result. However, this variable somehow shadows qualified variables with the name `it`. For instance, importing Test.Hspec, running any statement, and then trying to use Test.Hspec.it (qualified) results in an "out of scope" error. The following small program demonstrates this: {{{ import GHC import GhcMonad import Outputable import GHC.Paths main = runGhc (Just libdir) $ do flags <- getSessionDynFlags setSessionDynFlags (flags{ hscTarget = HscInterpreted, ghcLink = LinkInMemory}) imps <- mapM parseImportDecl ["import Prelude", "import Test.Hspec"] setContext (map IIDecl imps) -- With the next line, you get an "Not in scope" exception. -- If you comment out this runStmt, it runs without error and prints the type. runStmt "3" RunToCompletion exprType "Test.Hspec.it" >>= (liftIO . putStrLn . showPpr flags) }}} GHCi somehow avoids this, but I have no idea how and could not figure it out from the sources. What's going on? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8639 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8639: GHC API `runStmt` overrides qualified import of `it` variable -------------------------------------+------------------------------------ Reporter: agibiansky | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: GHC API | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by simonpj): Good point. I'll fix this. I think you missed out some code in the test: {{{ setSessionDynFlags (flags{ hscTarget = HscInterpreted, ghcLink = LinkInMemory}) * target <- guessTarget "Test/Hspec.hs" Nothing * setTargets [target] * load LoadAllTargets imps <- mapM parseImportDecl ["import Prelude", "import Test.Hspec"] }}} The lines marked * are important! Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8639#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8639: GHC API `runStmt` overrides qualified import of `it` variable -------------------------------------+------------------------------------ Reporter: agibiansky | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: GHC API | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by agibiansky): Simon, I'm not sure if this is relevant to the bug, but just FYI, the program I posted was complete. I did not have `Hspec.hs` as a target, I simply had the `hspec` package installed via `cabal install` (as a user normally would.) I just verified to make sure - if you copy and paste the entire program and compile with ghc 7.6.3, everything works (or doesn't work) as reported. Thanks for tackling this! -- Andrew -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8639#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8639: GHC API `runStmt` overrides qualified import of `it` variable -------------------------------------+------------------------------------ Reporter: agibiansky | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: GHC API | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by simonpj): Turns out that you need also {{{ runStmt "hFlush stdout" RunToCompletion }}} to make the output appear when redirecting. Weird. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8639#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8639: GHC API `runStmt` overrides qualified import of `it` variable
-------------------------------------+------------------------------------
Reporter: agibiansky | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: GHC API | Version: 7.6.3
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture: Unknown/Multiple
Type of failure: None/Unknown | Difficulty: Unknown
Test Case: | Blocked By:
Blocking: | Related Tickets:
-------------------------------------+------------------------------------
Comment (by Simon Peyton Jones

#8639: GHC API `runStmt` overrides qualified import of `it` variable
-------------------------------------+------------------------------------
Reporter: agibiansky | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: GHC API | Version: 7.6.3
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture: Unknown/Multiple
Type of failure: None/Unknown | Difficulty: Unknown
Test Case: | Blocked By:
Blocking: | Related Tickets:
-------------------------------------+------------------------------------
Comment (by Simon Peyton Jones

#8639: GHC API `runStmt` overrides qualified import of `it` variable
-------------------------------------+------------------------------------
Reporter: agibiansky | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: GHC API | Version: 7.6.3
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture: Unknown/Multiple
Type of failure: None/Unknown | Difficulty: Unknown
Test Case: | Blocked By:
Blocking: | Related Tickets:
-------------------------------------+------------------------------------
Comment (by Simon Peyton Jones

#8639: GHC API `runStmt` overrides qualified import of `it` variable -------------------------------------------------+------------------------- Reporter: agibiansky | Owner: Type: bug | Status: Priority: normal | closed Component: GHC API | Milestone: Resolution: fixed | Version: 7.6.3 Operating System: Unknown/Multiple | Keywords: Type of failure: None/Unknown | Architecture: Test Case: ghc-api/T8639_api, | Unknown/Multiple ghci/scripts/T8639 | Difficulty: Blocking: | Unknown | Blocked By: | Related Tickets: -------------------------------------------------+------------------------- Changes (by simonpj): * status: new => closed * testcase: => ghc-api/T8639_api, ghci/scripts/T8639 * resolution: => fixed Comment: Thanks for identifying this so well. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8639#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC