[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 <simonpj@…>): In [changeset:"5dffb4ac14b53362ebe9a67c5c6a01f9c9c25229/ghc"]: {{{ #!CommitTicketReference repository="ghc" revision="5dffb4ac14b53362ebe9a67c5c6a01f9c9c25229" Refactor the way shadowing in handled in GHCi If you say ghci> import Foo( T ) ghci> data T = MkT ghci> data T = XXX then the second 'data T' should shadow the first. But the qualified Foo.T should still be available. We really weren't handling this correctly at all, resulting in Trac #8639 and #8628 among others This patch: * Add RdrName.extendGlobalRdrEnv, which does shadowing properly * Change HscTypes.icExtendGblRdrEnv (was badly-named icPlusGblRdrEnv) to use the new function * Change RnNames.extendGobalRdrEnvRn to use the new function * Move gresFrom Avails into RdrName * Better pprGlobalRdrEnv function in RdrName }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8639#comment:4> 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 <simonpj@…>): In [changeset:"0a0ca8097d52838bf6faa883dfab4f84a7e89527/testsuite"]: {{{ #!CommitTicketReference repository="testsuite" revision="0a0ca8097d52838bf6faa883dfab4f84a7e89527" Test Trac #8639 (just the GHCi version) }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8639#comment:5> 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 <simonpj@…>): In [changeset:"b56bee2c2340f0ce8f6759e989093c18d7a7bd40/testsuite"]: {{{ #!CommitTicketReference repository="testsuite" revision="b56bee2c2340f0ce8f6759e989093c18d7a7bd40" Test Trac #8639 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8639#comment:6> 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: 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