Commit 92f81841 authored by Roland Senn's avatar Roland Senn Committed by Krzysztof Gogolewski

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
parent 921fd890
......@@ -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
......
x :: String -> String
x s = print (reverse s + 1)
myshow :: (String -> String) -> String
myshow x = show x
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)
......@@ -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, [''])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment