diff options
author | Roland Senn <rsx@bluewin.ch> | 2020-02-17 10:58:32 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-02-20 21:21:28 -0500 |
commit | 8b76d4574d703ee66f346775d408220fdddb8155 (patch) | |
tree | 2db0fd5588029d788dc36dba42ab97b9ed468e82 /compiler | |
parent | 65b7256a88ae2bd878da5d026e4183cba6f6eedf (diff) | |
download | haskell-8b76d4574d703ee66f346775d408220fdddb8155.tar.gz |
Fix #17832: Weird handling of exports named main in 8.10-rc1
Switching from `lookupGlobalOccRn_maybe` to `lookupInfoOccRn`
to check whether a `main` function is in scope. Unfortunately
`lookupGlobalOccRn_maybe` complains if there are multiple `main`
functions in scope.
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/GHC/Rename/Env.hs | 3 | ||||
-rw-r--r-- | compiler/typecheck/TcRnExports.hs | 15 |
2 files changed, 13 insertions, 5 deletions
diff --git a/compiler/GHC/Rename/Env.hs b/compiler/GHC/Rename/Env.hs index 964b49412a..d300761a68 100644 --- a/compiler/GHC/Rename/Env.hs +++ b/compiler/GHC/Rename/Env.hs @@ -1062,6 +1062,9 @@ lookupInfoOccRn :: RdrName -> RnM [Name] -- It finds all the GREs that RdrName could mean, not complaining -- about ambiguity, but rather returning them all -- C.f. #9881 +-- lookupInfoOccRn is also used in situations where we check for +-- at least one definition of the RdrName, not complaining about +-- multiple definitions. (See #17832) lookupInfoOccRn rdr_name = lookupExactOrOrig rdr_name (:[]) $ do { rdr_env <- getGlobalRdrEnv diff --git a/compiler/typecheck/TcRnExports.hs b/compiler/typecheck/TcRnExports.hs index 950b8572e8..5a4e21d5c1 100644 --- a/compiler/typecheck/TcRnExports.hs +++ b/compiler/typecheck/TcRnExports.hs @@ -176,9 +176,10 @@ tcRnExports explicit_mod exports Just main_fun | is_main_mod -> mkUnqual varName (fsLit main_fun) _ -> main_RDR_Unqual - ; has_main <- lookupGlobalOccRn_maybe default_main >>= return . isJust - -- If the module has no explicit header, and it has a main function, - -- then we add a header like "module Main(main) where ..." (#13839) + ; has_main <- (not . null) <$> lookupInfoOccRn default_main -- #17832 + -- If a module has no explicit header, and it has one or more main + -- functions in scope, then add a header like + -- "module Main(main) where ..." #13839 -- See Note [Modules without a module header] ; let real_exports | explicit_mod = exports @@ -451,12 +452,16 @@ The Haskell 2010 report says in section 5.1: For modules without a module header, this is implemented the following way: -If the module has a main function: - Then create a module header and export the main function. +If the module has a main function in scope: + Then create a module header and export the main function, + as if a module header like ‘module Main(main) where...’ would exist. This has the effect to mark the main function and all top level functions called directly or indirectly via main as 'used', and later on, unused top-level functions can be reported correctly. There is no distinction between GHC and GHCi. +If the module has several main functions in scope: + Then generate a header as above. The ambiguity is reported later in + module `TcRnDriver.hs` function `check_main`. If the module has NO main function: Then export all top-level functions. This marks all top level functions as 'used'. |