[commit: ghc] master: Do not print the result of 'main' after invoking ':main' (fixes #9086). (55e7ab1)
git at git.haskell.org
git at git.haskell.org
Mon Jul 7 07:53:23 UTC 2014
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/55e7ab1210975e6276f3cab3ac0e1f35bcd772f0/ghc
>---------------------------------------------------------------
commit 55e7ab1210975e6276f3cab3ac0e1f35bcd772f0
Author: Gintautas Miliauskas <gintautas.miliauskas at gmail.com>
Date: Sun Jun 8 11:49:29 2014 +0000
Do not print the result of 'main' after invoking ':main' (fixes #9086).
>---------------------------------------------------------------
55e7ab1210975e6276f3cab3ac0e1f35bcd772f0
ghc/InteractiveUI.hs | 7 ++++---
testsuite/tests/ghc-e/should_run/Makefile | 2 ++
testsuite/tests/ghc-e/should_run/T9086.hs | 1 +
testsuite/tests/ghc-e/should_run/all.T | 1 +
testsuite/tests/ghci/scripts/T9086b.script | 2 ++
.../{ffi/should_run/ffi021.stdout => ghci/scripts/T9086b.stdout} | 0
testsuite/tests/ghci/scripts/all.T | 1 +
7 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/ghc/InteractiveUI.hs b/ghc/InteractiveUI.hs
index 0a56799..c3d9f25 100644
--- a/ghc/InteractiveUI.hs
+++ b/ghc/InteractiveUI.hs
@@ -1141,9 +1141,10 @@ runMain s = case toArgs s of
Left err -> liftIO (hPutStrLn stderr err)
Right args ->
do dflags <- getDynFlags
- case mainFunIs dflags of
- Nothing -> doWithArgs args "main"
- Just f -> doWithArgs args f
+ let main = fromMaybe "main" (mainFunIs dflags)
+ -- Wrap the main function in 'void' to discard its value instead
+ -- of printing it (#9086). See Haskell 2010 report Chapter 5.
+ doWithArgs args $ "Control.Monad.void (" ++ main ++ ")"
-----------------------------------------------------------------------------
-- :run
diff --git a/testsuite/tests/ghc-e/should_run/Makefile b/testsuite/tests/ghc-e/should_run/Makefile
index 1971004..5ed1ec2 100644
--- a/testsuite/tests/ghc-e/should_run/Makefile
+++ b/testsuite/tests/ghc-e/should_run/Makefile
@@ -30,3 +30,5 @@ T3890:
T7299:
'$(TEST_HC)' $(TEST_HC_OPTS) -ignore-dot-ghci -e "Control.Concurrent.threadDelay (1000 * 1000)"
+T9086:
+ '$(TEST_HC)' $(TEST_HC_OPTS) -ignore-dot-ghci -e ":main" T9086.hs
diff --git a/testsuite/tests/ghc-e/should_run/T9086.hs b/testsuite/tests/ghc-e/should_run/T9086.hs
new file mode 100644
index 0000000..a2b4ace
--- /dev/null
+++ b/testsuite/tests/ghc-e/should_run/T9086.hs
@@ -0,0 +1 @@
+main = return "this should not be printed"
diff --git a/testsuite/tests/ghc-e/should_run/all.T b/testsuite/tests/ghc-e/should_run/all.T
index 4ab7567..9f64918 100644
--- a/testsuite/tests/ghc-e/should_run/all.T
+++ b/testsuite/tests/ghc-e/should_run/all.T
@@ -14,3 +14,4 @@ test('T2228',
test('T2636', req_interp, run_command, ['$MAKE --no-print-directory -s T2636'])
test('T3890', req_interp, run_command, ['$MAKE --no-print-directory -s T3890'])
test('T7299', req_interp, run_command, ['$MAKE --no-print-directory -s T7299'])
+test('T9086', req_interp, run_command, ['$MAKE --no-print-directory -s T9086'])
diff --git a/testsuite/tests/ghci/scripts/T9086b.script b/testsuite/tests/ghci/scripts/T9086b.script
new file mode 100644
index 0000000..d60156a
--- /dev/null
+++ b/testsuite/tests/ghci/scripts/T9086b.script
@@ -0,0 +1,2 @@
+let main = do { putStrLn "hello"; return "discarded" }
+:main
diff --git a/testsuite/tests/ffi/should_run/ffi021.stdout b/testsuite/tests/ghci/scripts/T9086b.stdout
similarity index 100%
copy from testsuite/tests/ffi/should_run/ffi021.stdout
copy to testsuite/tests/ghci/scripts/T9086b.stdout
diff --git a/testsuite/tests/ghci/scripts/all.T b/testsuite/tests/ghci/scripts/all.T
index b71dfd1..d1e67eb 100755
--- a/testsuite/tests/ghci/scripts/all.T
+++ b/testsuite/tests/ghci/scripts/all.T
@@ -175,3 +175,4 @@ test('T8931', normal, ghci_script, ['T8931.script'])
test('T8959', normal, ghci_script, ['T8959.script'])
test('T8959b', expect_broken(8959), ghci_script, ['T8959b.script'])
test('T9181', normal, ghci_script, ['T9181.script'])
+test('T9086b', normal, ghci_script, ['T9086b.script'])
More information about the ghc-commits
mailing list