From a305b3375d72007a41e02ec6e986995713dbe2a4 Mon Sep 17 00:00:00 2001 From: Jaro Date: Wed, 26 Feb 2025 18:35:09 +0000 Subject: [PATCH 1/3] Add GHC-67120 `main` not defined --- message-index/messages/GHC-67120/index.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 message-index/messages/GHC-67120/index.md diff --git a/message-index/messages/GHC-67120/index.md b/message-index/messages/GHC-67120/index.md new file mode 100644 index 00000000..25a2da29 --- /dev/null +++ b/message-index/messages/GHC-67120/index.md @@ -0,0 +1,16 @@ +--- +title: ‘main’ not defined +summary: The IO action ‘main’ is not defined in module ‘Main’. +introduced: 9.8.1 +severity: error +--- + +GHC expects the `Main` module to define a function called `main` which it can use as the entry point of your program. + +This error can also occur in unnamed modules, because GHC will default to the module name `Main` for such modules. + +If you just want GHC to produce an object file without an entry point, then you can give your module a name other than `Main` by putting a module header at the top of your file (below language pragmas and compiler options), for example as follows: + +``` +module Foo where +``` From a40822f46f784f3abbb8cf360e654872255bec75 Mon Sep 17 00:00:00 2001 From: Jaro Reinders Date: Fri, 28 Feb 2025 12:04:43 +0100 Subject: [PATCH 2/3] Put more effort into GHC-67120 --- .../messages/GHC-67120/example1/after/Lib.hs | 4 ++ .../messages/GHC-67120/example1/before/Lib.hs | 2 + .../messages/GHC-67120/example1/index.md | 9 ++++ .../messages/GHC-67120/example2/after/Main.hs | 2 + .../GHC-67120/example2/before/Main.hs | 2 + .../messages/GHC-67120/example2/index.md | 7 ++++ message-index/messages/GHC-67120/index.md | 41 +++++++++++++++++-- 7 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 message-index/messages/GHC-67120/example1/after/Lib.hs create mode 100644 message-index/messages/GHC-67120/example1/before/Lib.hs create mode 100644 message-index/messages/GHC-67120/example1/index.md create mode 100644 message-index/messages/GHC-67120/example2/after/Main.hs create mode 100644 message-index/messages/GHC-67120/example2/before/Main.hs create mode 100644 message-index/messages/GHC-67120/example2/index.md diff --git a/message-index/messages/GHC-67120/example1/after/Lib.hs b/message-index/messages/GHC-67120/example1/after/Lib.hs new file mode 100644 index 00000000..4cf406c5 --- /dev/null +++ b/message-index/messages/GHC-67120/example1/after/Lib.hs @@ -0,0 +1,4 @@ +module Lib where + +factorial :: Int -> Int +factorial n = product [1..n] diff --git a/message-index/messages/GHC-67120/example1/before/Lib.hs b/message-index/messages/GHC-67120/example1/before/Lib.hs new file mode 100644 index 00000000..9ae85065 --- /dev/null +++ b/message-index/messages/GHC-67120/example1/before/Lib.hs @@ -0,0 +1,2 @@ +factorial :: Int -> Int +factorial n = product [1..n] diff --git a/message-index/messages/GHC-67120/example1/index.md b/message-index/messages/GHC-67120/example1/index.md new file mode 100644 index 00000000..cde5ee14 --- /dev/null +++ b/message-index/messages/GHC-67120/example1/index.md @@ -0,0 +1,9 @@ +--- +title: Missing module header +--- + +In this example, the file `Lib.hs` is intended to contain a module called `Lib` +which is not supposed to be the main module. However, the file is missing a +module header, so GHC defaults to the module name `Main` and expects the `main` +function. Adding an explicit module header with the name `Lib` solves this +issue. diff --git a/message-index/messages/GHC-67120/example2/after/Main.hs b/message-index/messages/GHC-67120/example2/after/Main.hs new file mode 100644 index 00000000..ecf15d6d --- /dev/null +++ b/message-index/messages/GHC-67120/example2/after/Main.hs @@ -0,0 +1,2 @@ +main :: IO () +main = putStrLn "Hello, World!" diff --git a/message-index/messages/GHC-67120/example2/before/Main.hs b/message-index/messages/GHC-67120/example2/before/Main.hs new file mode 100644 index 00000000..2380be4f --- /dev/null +++ b/message-index/messages/GHC-67120/example2/before/Main.hs @@ -0,0 +1,2 @@ +notMain :: IO () +notMain = putStrLn "Hello, World!" diff --git a/message-index/messages/GHC-67120/example2/index.md b/message-index/messages/GHC-67120/example2/index.md new file mode 100644 index 00000000..81e2d3c1 --- /dev/null +++ b/message-index/messages/GHC-67120/example2/index.md @@ -0,0 +1,7 @@ +--- +title: `main` has wrong name +--- + +In this example, the `notMain` value is the intended entry point of the program, +but it is not called `main` so GHC does not find it. Renaming `notMain` to +`main` solves the issue. diff --git a/message-index/messages/GHC-67120/index.md b/message-index/messages/GHC-67120/index.md index 25a2da29..e1295afd 100644 --- a/message-index/messages/GHC-67120/index.md +++ b/message-index/messages/GHC-67120/index.md @@ -1,16 +1,49 @@ --- -title: ‘main’ not defined +title: Missing main summary: The IO action ‘main’ is not defined in module ‘Main’. introduced: 9.8.1 severity: error --- -GHC expects the `Main` module to define a function called `main` which it can use as the entry point of your program. +GHC expects the `Main` module to define a function called `main` which it can +use as the entry point of your program. -This error can also occur in unnamed modules, because GHC will default to the module name `Main` for such modules. +This error can also occur in unnamed modules, because GHC will default to the +module name `Main` for such modules. -If you just want GHC to produce an object file without an entry point, then you can give your module a name other than `Main` by putting a module header at the top of your file (below language pragmas and compiler options), for example as follows: +If you just want GHC to produce an object file without an entry point, then you +can give your module a name other than `Main` by putting a module header at the +top of your file (below language pragmas and compiler options), for example as +follows: ``` module Foo where ``` + +The conventions around `main` are defined in the second paragraph of Chapter 5 +of [The Haskell 2010 Report](https://www.haskell.org/onlinereport/haskell2010/haskellch5.html#x11-980005), + +> A Haskell program is a collection of modules, one of which, by convention, +> must be called `Main` and must export the value `main`. The value of the +> program is the value of the identifier `main` in module `Main`, which must be +> a computation of type `IO t` for some type `t` (see Chapter 7). When the +> program is executed, the computation `main` is performed, and its result (of +> type `t`) is discarded. + +## Example error text + +``` +example1/before/Lib.hs:1:1: error: [GHC-67120] + The IO action ‘main’ is not defined in module ‘Main’ + | +1 | factorial :: Int -> Int + | ^ +``` + +``` +example2/before/Main.hs:1:1: error: [GHC-67120] + The IO action ‘main’ is not defined in module ‘Main’ + | +1 | notMain :: IO () + | ^ +``` From 82d60d6aea3ade30194330946986dab22f2219d8 Mon Sep 17 00:00:00 2001 From: Jaro Reinders Date: Fri, 28 Feb 2025 12:09:17 +0100 Subject: [PATCH 3/3] Fix YAML parsing error for GHC-67120 --- message-index/messages/GHC-67120/example2/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/message-index/messages/GHC-67120/example2/index.md b/message-index/messages/GHC-67120/example2/index.md index 81e2d3c1..b5cfe809 100644 --- a/message-index/messages/GHC-67120/example2/index.md +++ b/message-index/messages/GHC-67120/example2/index.md @@ -1,5 +1,5 @@ --- -title: `main` has wrong name +title: main has wrong name --- In this example, the `notMain` value is the intended entry point of the program,