summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchessai <chessai1996@gmail.com>2018-10-02 14:46:08 +0200
committerKrzysztof Gogolewski <krz.gogolewski@gmail.com>2018-10-02 16:00:19 +0200
commitabfb91fb0ea27eb618f297b1d3ba60cfa021afe0 (patch)
treef35b012fb723e44c015a97c69c128019755fd580
parentcaffff1238097821cd2879f7285010a6565afd52 (diff)
downloadhaskell-abfb91fb0ea27eb618f297b1d3ba60cfa021afe0.tar.gz
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: https://phabricator.haskell.org/D5189
-rw-r--r--.gitignore8
-rw-r--r--compiler/typecheck/TcRnExports.hs13
-rw-r--r--docs/users_guide/bugs.rst28
-rw-r--r--testsuite/tests/module/T13704.hs3
-rw-r--r--testsuite/tests/module/all.T2
5 files changed, 45 insertions, 9 deletions
diff --git a/.gitignore b/.gitignore
index c72d044473..83fa7ececb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -208,4 +208,10 @@ GIT_COMMIT_ID
# -----------------------------------------------------------------------------
# Output of ghc-in-ghci
-/.ghci-objects/ \ No newline at end of file
+/.ghci-objects/
+
+# -----------------------------------------------------------------------------
+# ghc.nix
+ghc.nix/
+
+
diff --git a/compiler/typecheck/TcRnExports.hs b/compiler/typecheck/TcRnExports.hs
index dbe2b4b22b..1b57608a41 100644
--- a/compiler/typecheck/TcRnExports.hs
+++ b/compiler/typecheck/TcRnExports.hs
@@ -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
diff --git a/docs/users_guide/bugs.rst b/docs/users_guide/bugs.rst
index aee8dc5842..0290622b62 100644
--- a/docs/users_guide/bugs.rst
+++ b/docs/users_guide/bugs.rst
@@ -173,6 +173,34 @@ same context. For example, this is fine: ::
.. _infelicities-Modules:
+Default Module headers with -main-is
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+The Haskell2010 report specifies in <https://www.haskell.org/onlinereport/haskell2010/haskellch5.html#x11-990005.1> 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
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/testsuite/tests/module/T13704.hs b/testsuite/tests/module/T13704.hs
new file mode 100644
index 0000000000..38b1cb73fc
--- /dev/null
+++ b/testsuite/tests/module/T13704.hs
@@ -0,0 +1,3 @@
+program = return ()
+
+-- meant to be compiled with 'ghc -main-is Main.program T13704.hs'
diff --git a/testsuite/tests/module/all.T b/testsuite/tests/module/all.T
index e862413897..dbba44f0ba 100644
--- a/testsuite/tests/module/all.T
+++ b/testsuite/tests/module/all.T
@@ -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'])