diff --git a/compiler/main/GhcMake.hs b/compiler/main/GhcMake.hs index ba21e5b94196e690ca6835228fa6939b7ffacf5c..2ea3816f947f58d636b200d55afdbac894a192cb 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 0000000000000000000000000000000000000000..9101fbd40ada5d47b499a48e62cb4ccd7f67ef71 --- /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 0000000000000000000000000000000000000000..91faa5087cb9cd9357a0b9f36b38559eba3914a6 --- /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 0000000000000000000000000000000000000000..3ae52a3ef7cdf41377b5e7cc6916dd95393f1034 --- /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 0000000000000000000000000000000000000000..f068d6516dd42551c0410a5f113c457a3a8b6ee2 --- /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'])