summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGintautas Miliauskas <gintautas.miliauskas@gmail.com>2014-06-08 11:49:29 +0000
committerJoachim Breitner <mail@joachim-breitner.de>2014-07-07 09:21:13 +0200
commit55e7ab1210975e6276f3cab3ac0e1f35bcd772f0 (patch)
treee5cf32b00fbb442d711e999359bfa6fda671ec6e
parentfa8553de237a2f91f8551d69ef604c1d8a007b5f (diff)
downloadhaskell-55e7ab1210975e6276f3cab3ac0e1f35bcd772f0.tar.gz
Do not print the result of 'main' after invoking ':main' (fixes #9086).
-rw-r--r--ghc/InteractiveUI.hs7
-rw-r--r--testsuite/tests/ghc-e/should_run/Makefile2
-rw-r--r--testsuite/tests/ghc-e/should_run/T9086.hs1
-rw-r--r--testsuite/tests/ghc-e/should_run/all.T1
-rw-r--r--testsuite/tests/ghci/scripts/T9086b.script2
-rw-r--r--testsuite/tests/ghci/scripts/T9086b.stdout1
-rwxr-xr-xtestsuite/tests/ghci/scripts/all.T1
7 files changed, 12 insertions, 3 deletions
diff --git a/ghc/InteractiveUI.hs b/ghc/InteractiveUI.hs
index 0a56799679..c3d9f25754 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 1971004d4c..5ed1ec2e6c 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 0000000000..a2b4ace33a
--- /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 4ab7567358..9f6491819d 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 0000000000..d60156ad02
--- /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/ghci/scripts/T9086b.stdout b/testsuite/tests/ghci/scripts/T9086b.stdout
new file mode 100644
index 0000000000..ce01362503
--- /dev/null
+++ b/testsuite/tests/ghci/scripts/T9086b.stdout
@@ -0,0 +1 @@
+hello
diff --git a/testsuite/tests/ghci/scripts/all.T b/testsuite/tests/ghci/scripts/all.T
index b71dfd14ce..d1e67ebeca 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'])