Commit abfb91fb authored by chessai's avatar chessai Committed by Krzysztof Gogolewski

resolve T13704

Summary: allow -main-is to change export list for default module
header, allowing one to change the entry point to one's program.

Test Plan: ./validate

Reviewers: bgamari, nomeata, mpickering

Reviewed By: mpickering

Subscribers: mpickering, rwbarton, carter

GHC Trac Issues: #13704

Differential Revision:
parent caffff12
......@@ -208,4 +208,10 @@ GIT_COMMIT_ID
# -----------------------------------------------------------------------------
# Output of ghc-in-ghci
\ No newline at end of file
# -----------------------------------------------------------------------------
# ghc.nix
......@@ -33,7 +33,7 @@ import DataCon
import PatSyn
import Maybes
import Util (capitalise)
import FastString (fsLit)
import Control.Monad
import DynFlags
......@@ -124,19 +124,18 @@ tcRnExports explicit_mod exports
-- list, to avoid bleating about re-exporting a deprecated
-- thing (especially via 'module Foo' export item)
do {
-- If the module header is omitted altogether, then behave
-- as if the user had written "module Main(main) where..."
-- EXCEPT in interactive mode, when we behave as if he had
-- In interactive mode, we behave as if he had
-- written "module Main where ..."
-- Reason: don't want to complain about 'main' not in scope
-- in interactive mode
; dflags <- getDynFlags
; let default_main = case mainFunIs dflags of
Just main_fun -> mkUnqual varName (fsLit main_fun)
Nothing -> main_RDR_Unqual
; let real_exports
| explicit_mod = exports
| ghcLink dflags == LinkInMemory = Nothing
| otherwise
= Just (noLoc [noLoc (IEVar noExt
(noLoc (IEName $ noLoc main_RDR_Unqual)))])
(noLoc (IEName $ noLoc default_main)))])
-- ToDo: the 'noLoc' here is unhelpful if 'main'
-- turns out to be out of scope
......@@ -173,6 +173,34 @@ same context. For example, this is fine: ::
.. _infelicities-Modules:
Default Module headers with -main-is
The Haskell2010 report specifies in <> that
"An abbreviated form of module, consisting only of the module body,
is permitted. If this is used, the header is assumed to be
`module Main(main) where`."
Consider the following program: ::
-- file: Main.hs
program :: IO ()
program = return ()
Under the report, this would fail with ``ghc -main-is Main.program Main.hs``
with the following errors: ::
Main.hs:1:1: error:
Not in scope: 'main'
Perhaps you meant 'min' (imported from Prelude)
Main.hs:1:1: error:
The main IO action 'program' is not exported by module 'Main'
GHC's flag '-main-is' allows one to change the entry point name so that
the above example would succeed.
Module system and interface files
program = return ()
-- meant to be compiled with 'ghc -main-is Main.program T13704.hs'
......@@ -284,4 +284,4 @@ test('T11970B', normal, compile_fail, [''])
test('MultiExport', normal, compile, [''])
test('T13528', normal, compile, [''])
test('T13622', normal, compile, [''])
test('T13704', normal, compile, ['-main-is Main.program'])
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment