diff options
author | Roland Senn <rsx@bluewin.ch> | 2018-11-17 12:24:27 +0100 |
---|---|---|
committer | Krzysztof Gogolewski <krz.gogolewski@gmail.com> | 2018-11-17 13:52:20 +0100 |
commit | 92f81841e885f081bbb079d0dca6eb50b9043d4b (patch) | |
tree | 57e370334d9c9b7220a402de89f73dfbd80ce357 | |
parent | 921fd890abe0e7267962c9439098b03c94ebdb9b (diff) | |
download | haskell-92f81841e885f081bbb079d0dca6eb50b9043d4b.tar.gz |
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
-rw-r--r-- | compiler/typecheck/TcRnDriver.hs | 10 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_fail/T12906.hs | 5 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_fail/T12906.stderr | 10 | ||||
-rw-r--r-- | 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 a3e2a2f433..3e8d043276 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 0000000000..80a10f33f6 --- /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 0000000000..c74fd97bbc --- /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 c3a9f510d0..3805315398 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, ['']) |