Opened 7 years ago

Closed 5 years ago

Last modified 4 years ago

#7765 closed bug (fixed)

Odd error message for `runghc` with missing `main` function.

Reported by: isaacdupree Owned by:
Priority: normal Milestone: 8.0.1
Component: Compiler Version: 7.6.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: module/T7765
Blocked By: Blocking:
Related Tickets: #414 Differential Rev(s): Phab:D649
Wiki Page:

Description

% cat what.hs
module Main where {}

% runghc what.hs
what.hs:1:33:
    Not in scope: `main'
    Perhaps you meant `min' (imported from Prelude)

'ghc what.hs' gives a rather more sensible message.

Change History (11)

comment:1 Changed 7 years ago by simonpj

difficulty: Unknown
Owner: set to igloo

Nothing to do with runghc really; its the -e mode:

ghc -e wombat what.hs
<interactive>:1:1: Not in scope: ‛womab’

But really it should say

what.hs:1:33:
    Not in scope: `main'
    Perhaps you meant `min' (imported from Prelude)

I'm not sure where the -e processing happens, and couldn't find it with a quick look. Ian, you've been refactoring the pipeline recently, might you look?

Simon

comment:2 Changed 7 years ago by igloo

I'm confused - doesn't it already say that?

comment:3 Changed 7 years ago by simonpj

Oh, sorry, I meant that it should say

what.hs:1:1: The function `main' is not defined in module `Main'

If instead it was

module What2 where
foo = True

and you said

ght -e bar What2.hs

then a "not in scope" message would make more sense. But in the common case of 'main' (which is what happens with runghc), the No main in Main message is better

Simon

comment:4 Changed 7 years ago by igloo

Milestone: 7.8.1

comment:5 Changed 6 years ago by igloo

Owner: igloo deleted

comment:6 Changed 6 years ago by thoughtpolice

Milestone: 7.8.37.10.1

Moving to 7.10.1

comment:7 Changed 5 years ago by thoughtpolice

Milestone: 7.10.17.12.1

Moving to 7.12.1 milestone; if you feel this is an error and should be addressed sooner, please move it back to the 7.10.1 milestone.

comment:8 Changed 5 years ago by thomie

Differential Rev(s): Phab:D649
Status: newpatch
Test Case: module/T7765

With Phab:D649, Main without main is always an error, regardless of the mode of operation: ghc, ghci or runhaskell (=ghc -e main).

Version 0, edited 5 years ago by thomie (next)

comment:9 Changed 5 years ago by Austin Seipp <austin@…>

In 0fa20726b0587530712677e50a56c2b03ba43095/ghc:

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

Summary:
GHC does 2 validation checks for module `Main`:
* does `main` exist
* is `main` exported (#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.

Reviewers: austin

Reviewed By: austin

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D649

GHC Trac Issues: #7765

comment:10 Changed 5 years ago by thoughtpolice

Resolution: fixed
Status: patchclosed

Merged, thanks!

comment:11 Changed 4 years ago by thoughtpolice

Milestone: 7.12.18.0.1

Milestone renamed

Note: See TracTickets for help on using tickets.