From 1637e4d16d28223aac66100cf7308d76a2a7ee7c Mon Sep 17 00:00:00 2001 From: Thomas Miedema Date: Sat, 19 Sep 2015 16:14:47 +0200 Subject: [PATCH] Driver: --make -o without Main should be an error (#10895) Reviewed by: austin Differential Revision: https://phabricator.haskell.org/D1253 --- compiler/main/GhcMake.hs | 20 ++++++++++--------- testsuite/tests/driver/should_fail/Makefile | 3 +++ testsuite/tests/driver/should_fail/T10895.hs | 1 + .../tests/driver/should_fail/T10895.stderr | 4 ++++ testsuite/tests/driver/should_fail/all.T | 2 ++ 5 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 testsuite/tests/driver/should_fail/Makefile create mode 100644 testsuite/tests/driver/should_fail/T10895.hs create mode 100644 testsuite/tests/driver/should_fail/T10895.stderr create mode 100644 testsuite/tests/driver/should_fail/all.T diff --git a/compiler/main/GhcMake.hs b/compiler/main/GhcMake.hs index ba21e5b941..2ea3816f94 100644 --- a/compiler/main/GhcMake.hs +++ b/compiler/main/GhcMake.hs @@ -325,18 +325,20 @@ load how_much = do a_root_is_Main = any ((==main_mod).ms_mod) mod_graph do_linking = a_root_is_Main || no_hs_main || ghcLink dflags == LinkDynLib || ghcLink dflags == LinkStaticLib - when (ghcLink dflags == LinkBinary - && isJust ofile && not do_linking) $ - liftIO $ debugTraceMsg dflags 1 $ - text ("Warning: output was redirected with -o, " ++ - "but no output will be generated\n" ++ - "because there is no " ++ - moduleNameString (moduleName main_mod) ++ " module.") - -- link everything together linkresult <- liftIO $ link (ghcLink dflags) dflags do_linking (hsc_HPT hsc_env1) - loadFinish Succeeded linkresult + if ghcLink dflags == LinkBinary && isJust ofile && not do_linking + then do + liftIO $ errorMsg dflags $ text + ("output was redirected with -o, " ++ + "but no output will be generated\n" ++ + "because there is no " ++ + moduleNameString (moduleName main_mod) ++ " module.") + -- This should be an error, not a warning (#10895). + loadFinish Failed linkresult + else + loadFinish Succeeded linkresult else -- Tricky. We need to back out the effects of compiling any diff --git a/testsuite/tests/driver/should_fail/Makefile b/testsuite/tests/driver/should_fail/Makefile new file mode 100644 index 0000000000..9101fbd40a --- /dev/null +++ b/testsuite/tests/driver/should_fail/Makefile @@ -0,0 +1,3 @@ +TOP=../../.. +include $(TOP)/mk/boilerplate.mk +include $(TOP)/mk/test.mk diff --git a/testsuite/tests/driver/should_fail/T10895.hs b/testsuite/tests/driver/should_fail/T10895.hs new file mode 100644 index 0000000000..91faa5087c --- /dev/null +++ b/testsuite/tests/driver/should_fail/T10895.hs @@ -0,0 +1 @@ +module NotMain where diff --git a/testsuite/tests/driver/should_fail/T10895.stderr b/testsuite/tests/driver/should_fail/T10895.stderr new file mode 100644 index 0000000000..3ae52a3ef7 --- /dev/null +++ b/testsuite/tests/driver/should_fail/T10895.stderr @@ -0,0 +1,4 @@ + +: error: + output was redirected with -o, but no output will be generated +because there is no Main module. diff --git a/testsuite/tests/driver/should_fail/all.T b/testsuite/tests/driver/should_fail/all.T new file mode 100644 index 0000000000..f068d6516d --- /dev/null +++ b/testsuite/tests/driver/should_fail/all.T @@ -0,0 +1,2 @@ +# --make -o without Main should be an error, not a warning. +test('T10895', normal, multimod_compile_fail, ['T10895.hs', '-v0 -o dummy']) -- GitLab