[commit: ghc] master: Fix #12906: GHC fails to typecheck Main module without main (92f8184)

git at git.haskell.org git at git.haskell.org
Sat Nov 17 12:52:54 UTC 2018


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/92f81841e885f081bbb079d0dca6eb50b9043d4b/ghc

>---------------------------------------------------------------

commit 92f81841e885f081bbb079d0dca6eb50b9043d4b
Author: Roland Senn <rsx at bluewin.ch>
Date:   Sat Nov 17 12:24:27 2018 +0100

    Fix #12906: GHC fails to typecheck Main module without main
    
    Summary: The function fail is no longer called immediately
    after adding the no-main error message to the TcM monad.
    The rest of the module will be typechecked.
    
    Test Plan: make test TEST=T12906
    
    Reviewers: dfeuer, RyanGlScott, ezyang, mpickering, bgamari
    
    Reviewed By: RyanGlScott
    
    Subscribers: rwbarton, carter
    
    GHC Trac Issues: #12906
    
    Differential Revision: https://phabricator.haskell.org/D5338


>---------------------------------------------------------------

92f81841e885f081bbb079d0dca6eb50b9043d4b
 compiler/typecheck/TcRnDriver.hs                    | 10 +++++-----
 testsuite/tests/typecheck/should_fail/T12906.hs     |  5 +++++
 testsuite/tests/typecheck/should_fail/T12906.stderr | 10 ++++++++++
 testsuite/tests/typecheck/should_fail/all.T         |  4 +++-
 4 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/compiler/typecheck/TcRnDriver.hs b/compiler/typecheck/TcRnDriver.hs
index a3e2a2f..3e8d043 100644
--- a/compiler/typecheck/TcRnDriver.hs
+++ b/compiler/typecheck/TcRnDriver.hs
@@ -1732,11 +1732,11 @@ check_main dflags tcg_env explicit_mod_hdr
     main_fn     = getMainFun dflags
     interactive = ghcLink dflags == LinkInMemory
 
-    complain_no_main = checkTc (interactive && not explicit_mod_hdr) noMainMsg
-        -- In interactive mode, without an explicit module header, don't
-        -- worry about the absence of 'main'.
-        -- In other modes, fail altogether, so that we don't go on
-        -- and complain a second time when processing the export list.
+    complain_no_main = unless (interactive && not explicit_mod_hdr)
+                              (addErrTc noMainMsg)                  -- #12906
+        -- Without an explicit module header...
+          -- in interactive mode, don't worry about the absence of 'main'.
+          -- in other modes, add error message and go on with typechecking.
 
     mainCtxt  = text "When checking the type of the" <+> pp_main_fn
     noMainMsg = text "The" <+> pp_main_fn
diff --git a/testsuite/tests/typecheck/should_fail/T12906.hs b/testsuite/tests/typecheck/should_fail/T12906.hs
new file mode 100644
index 0000000..80a10f3
--- /dev/null
+++ b/testsuite/tests/typecheck/should_fail/T12906.hs
@@ -0,0 +1,5 @@
+x :: String -> String
+x s = print (reverse s + 1)
+
+myshow :: (String -> String) -> String
+myshow x = show x
diff --git a/testsuite/tests/typecheck/should_fail/T12906.stderr b/testsuite/tests/typecheck/should_fail/T12906.stderr
new file mode 100644
index 0000000..c74fd97
--- /dev/null
+++ b/testsuite/tests/typecheck/should_fail/T12906.stderr
@@ -0,0 +1,10 @@
+
+T12906.hs:1:1: error:
+    The IO action ‘main’ is not defined in module ‘Main’
+
+T12906.hs:2:7: error:
+    • Couldn't match type ‘IO ()’ with ‘[Char]’
+      Expected type: String
+        Actual type: IO ()
+    • In the expression: print (reverse s + 1)
+      In an equation for ‘x’: x s = print (reverse s + 1)
diff --git a/testsuite/tests/typecheck/should_fail/all.T b/testsuite/tests/typecheck/should_fail/all.T
index c3a9f51..3805315 100644
--- a/testsuite/tests/typecheck/should_fail/all.T
+++ b/testsuite/tests/typecheck/should_fail/all.T
@@ -141,7 +141,8 @@ test('tcfail154', normal, compile_fail, [''])
 test('tcfail155', normal, compile_fail, [''])
 test('tcfail156', normal, compile_fail, [''])
 test('tcfail157', normal, compile_fail, [''])
-test('tcfail158', normal, compile_fail, [''])
+# Skip tcfail158 until Trac ticket #15899 fixes the broken test
+test('tcfail158', skip, compile_fail, [''])
 test('tcfail159', normal, compile_fail, [''])
 test('tcfail160', normal, compile_fail, [''])
 test('tcfail161', normal, compile_fail, [''])
@@ -424,6 +425,7 @@ test('T12803', normal, compile_fail, [''])
 test('T12042', [extra_files(['T12042.hs', 'T12042a.hs', 'T12042.hs-boot'])], multimod_compile_fail, ['T12042', ''])
 test('T12966', normal, compile_fail, [''])
 test('T12837', normal, compile_fail, [''])
+test('T12906', normal, compile_fail, [''])
 test('T12918a', normal, compile_fail, [''])
 test('T12918b', normal, compile_fail, [''])
 test('T12921', normal, compile_fail, [''])



More information about the ghc-commits mailing list