Driver: --make -o without Main should be an error (#10895)
authorThomas Miedema <thomasmiedema@gmail.com>
Sat, 19 Sep 2015 14:14:47 +0000 (16:14 +0200)
committerThomas Miedema <thomasmiedema@gmail.com>
Sun, 20 Sep 2015 17:44:28 +0000 (19:44 +0200)
Reviewed by: austin

Differential Revision: https://phabricator.haskell.org/D1253

compiler/main/GhcMake.hs
testsuite/tests/driver/should_fail/Makefile [new file with mode: 0644]
testsuite/tests/driver/should_fail/T10895.hs [new file with mode: 0644]
testsuite/tests/driver/should_fail/T10895.stderr [new file with mode: 0644]
testsuite/tests/driver/should_fail/all.T [new file with mode: 0644]

index ba21e5b..2ea3816 100644 (file)
@@ -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 (file)
index 0000000..9101fbd
--- /dev/null
@@ -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 (file)
index 0000000..91faa50
--- /dev/null
@@ -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 (file)
index 0000000..3ae52a3
--- /dev/null
@@ -0,0 +1,4 @@
+
+<no location info>: 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 (file)
index 0000000..f068d65
--- /dev/null
@@ -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'])