Error out on `Main` without `main` in GHCi (#7765)
ClosedPublic

Authored by thomie on Feb 10 2015, 10:56 AM.

Details

Summary

GHC does 2 validation checks for module Main:

  • does main exist
  • is main exported (Trac #414)

The second check is done in ghc as well as in ghci (and runghc and ghc -e).
The first check however is currently not done in ghci, to prevent "'main' is
not in scope" errors when loading simple scripts. See commit d28ba8c8009 for
more information.

This commit tightens the special case for ghci. When the file does not contain
a main function, but does contain an explicit module header (i.e. "module Main
where"), then /do/ raise an error in ghci (and runghc and ghc -e) as well

Test Plan

module/T7765: a module Main with an explicit module header but without a
main function should be an error for all Ways.

Additionaly: delete test module/mod174. It was added in commit 5a54c38, but it
is a duplicate of module/T414.

Diff Detail

Repository
rGHC Glasgow Haskell Compiler
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
thomie updated this revision to Diff 2213.Feb 10 2015, 10:56 AM
thomie retitled this revision from to Error out on `Main` without `main` in GHCi (#7765).
thomie updated this object.
thomie edited the test plan for this revision. (Show Details)
thomie added a reviewer: austin.
thomie updated the Trac tickets for this revision.
thomie updated this revision to Diff 2214.Feb 10 2015, 11:04 AM

Fix typo

thomie updated this revision to Diff 2216.Feb 10 2015, 11:19 AM

Suppress warning

austin accepted this revision.Feb 10 2015, 3:19 PM
austin edited edge metadata.

LGTM.

This revision is now accepted and ready to land.Feb 10 2015, 3:19 PM
thomie planned changes to this revision.Feb 11 2015, 4:02 AM

This change would prevent GHCi from loading files without an explicit module declaration.

thomie updated this revision to Diff 2223.Feb 12 2015, 1:06 PM
thomie edited edge metadata.

To still allow files without explicit module headers to load in ghci, I
changed the logic to only raise an error when main is missing *and* the file
contains an explicit module header.

  • Rearrange some code
  • Cleanup some comments
  • Rename some test Modules
This revision is now accepted and ready to land.Feb 12 2015, 1:06 PM
thomie updated this object.Feb 12 2015, 1:11 PM
thomie edited the test plan for this revision. (Show Details)
thomie updated this revision to Diff 2225.Feb 12 2015, 2:30 PM
thomie updated this object.
thomie edited the test plan for this revision. (Show Details)

Validate

thomie updated this revision to Diff 2227.Feb 12 2015, 3:17 PM

Cleanup by adding tcg_mod_name to environment.

This revision was automatically updated to reflect the committed changes.