Commit 93f02b62 authored by Roland Senn's avatar Roland Senn Committed by Marge Bot

New fix for #11647. Avoid side effects like #17171

If a main module doesn't contain a header, we omit the check whether the main module is exported.
With this patch GHC, GHCi and runghc use the same code.
parent 0d31ccdd
Pipeline #10913 failed with stages
in 236 minutes and 58 seconds
......@@ -271,8 +271,10 @@ tcRnModuleTcRnM hsc_env mod_sum
; tcg_env <- tcRnExports explicit_mod_hdr export_ies
tcg_env
; traceRn "rn4b: after exports" empty
; -- Check main is exported(must be after tcRnExports)
checkMainExported tcg_env
; -- When a module header is specified,
-- check that the main module exports a main function.
-- (must be after tcRnExports)
when explicit_mod_hdr $ checkMainExported tcg_env
; -- Compare hi-boot iface (if any) with the real thing
-- Must be done after processing the exports
tcg_env <- checkHiBootIface tcg_env boot_info
......@@ -1801,11 +1803,10 @@ checkMainExported tcg_env
Just main_name ->
do { dflags <- getDynFlags
; let main_mod = mainModIs dflags
; when (ghcLink dflags /= LinkInMemory) $ -- #11647
checkTc (main_name `elem`
; checkTc (main_name `elem`
concatMap availNames (tcg_exports tcg_env)) $
text "The" <+> ppMainFn (nameRdrName main_name) <+>
text "is not exported by module" <+> quotes (ppr main_mod) }
text "The" <+> ppMainFn (nameRdrName main_name) <+>
text "is not exported by module" <+> quotes (ppr main_mod) }
ppMainFn :: RdrName -> SDoc
ppMainFn main_fn
......
......@@ -23,5 +23,10 @@ T11247:
-'$(RUNGHC)' foo.
-'$(RUNGHC)' foo.bar
T17171a:
'$(RUNGHC)' --ghc-arg=-Wall T17171a.hs
T17171b:
'$(RUNGHC)' --ghc-arg=-Wall T17171b.hs
T-signals-child:
-'$(RUNGHC)' T-signals-child.hs --runghc '$(RUNGHC)'
module Main () where
main :: IO ()
main = putStrLn "Main"
Main.hs:1:1: error:
The IO action ‘main’ is not exported by module ‘Main’
|
1 | module Main () where
| ^
module T17171b () where
main :: IO ()
main = putStrLn "NoMain"
T17171b.hs:4:1: warning: [-Wunused-top-binds]
Defined but not used: ‘main’
|
4 | main = putStrLn "NoMain"
| ^^^^
......@@ -6,6 +6,9 @@ test('T11247', [req_interp, expect_broken(11247)], makefile_test, [])
test('T6132', [when(opsys('darwin'), expect_broken(6132))], compile, [''])
test('T17171a', [req_interp, expect_fail], makefile_test, [])
test('T17171b', req_interp, makefile_test, [])
test('T-signals-child',
[ when(opsys('mingw32'), skip), req_interp
, only_ways(['threaded1', 'threaded2'])
......
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