diff --git a/CHANGES b/CHANGES index cfd4aca6..6f33b419 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +Unreleased + - Don't use unqualified references to `stderr` or `stdout` which may collide with definitions in user code. (#201) + Changes in 0.17 - #266: - doctest now annotates its internal marker string as a `String`, to prevent misbehaviour in `OverloadedStrings` environments. This has a theoretical chance of breakage; if you're affected, please open an issue. diff --git a/ghci-wrapper/src/Language/Haskell/GhciWrapper.hs b/ghci-wrapper/src/Language/Haskell/GhciWrapper.hs index 394d8f36..e9b10dac 100644 --- a/ghci-wrapper/src/Language/Haskell/GhciWrapper.hs +++ b/ghci-wrapper/src/Language/Haskell/GhciWrapper.hs @@ -54,20 +54,20 @@ new Config{..} args_ = do setMode stdin_ setMode stdout_ let interpreter = Interpreter {hIn = stdin_, hOut = stdout_, process = processHandle} - _ <- eval interpreter "import System.IO" - _ <- eval interpreter "import GHC.IO.Handle" + _ <- eval interpreter "import qualified System.IO" + _ <- eval interpreter "import qualified GHC.IO.Handle" -- The buffering of stdout and stderr is NoBuffering - _ <- eval interpreter "hDuplicateTo stdout stderr" + _ <- eval interpreter "GHC.IO.Handle.hDuplicateTo System.IO.stdout System.IO.stderr" -- Now the buffering of stderr is BlockBuffering Nothing -- In this situation, GHC 7.7 does not flush the buffer even when -- error happens. - _ <- eval interpreter "hSetBuffering stdout LineBuffering" - _ <- eval interpreter "hSetBuffering stderr LineBuffering" + _ <- eval interpreter "GHC.IO.Handle.hSetBuffering System.IO.stdout GHC.IO.Handle.LineBuffering" + _ <- eval interpreter "GHC.IO.Handle.hSetBuffering System.IO.stderr GHC.IO.Handle.LineBuffering" -- this is required on systems that don't use utf8 as default encoding (e.g. -- Windows) - _ <- eval interpreter "hSetEncoding stdout utf8" - _ <- eval interpreter "hSetEncoding stderr utf8" + _ <- eval interpreter "GHC.IO.Handle.hSetEncoding System.IO.stdout GHC.IO.Handle.utf8" + _ <- eval interpreter "GHC.IO.Handle.hSetEncoding System.IO.stderr GHC.IO.Handle.utf8" _ <- eval interpreter ":m - System.IO" _ <- eval interpreter ":m - GHC.IO.Handle" diff --git a/test/integration/local-stderr-binding/A.hs b/test/integration/local-stderr-binding/A.hs new file mode 100644 index 00000000..57b2cbbc --- /dev/null +++ b/test/integration/local-stderr-binding/A.hs @@ -0,0 +1,11 @@ +module A where + +stderr :: Bool +stderr = True + +stdout :: String +stdout = "hello" + +-- | +-- >>> 3 + 3 +-- 6 diff --git a/test/integration/system-io-imported/A.hs b/test/integration/system-io-imported/A.hs new file mode 100644 index 00000000..ad9f9d91 --- /dev/null +++ b/test/integration/system-io-imported/A.hs @@ -0,0 +1,10 @@ +module A where + +import System.IO + +-- ghci-wrapper needs to poke around with System.IO itself, and unloads the module once it's done. Test to make sure legitimate uses of System.IO don't get lost in the wash. + +-- | +-- >>> ReadMode +-- ReadMode +