bad error message for multiple modules in the same file
consider this file:
module MyMod where
foo :: Int
foo = 3
module Main (main) where
import MyMod (foo)
main :: IO ()
main = print foo
The layout rule dictates that this parses properly (the first module clause ends when the second "module" gives a parse error, just like "in" ends a "let"); this gets the same error:
module MyMod where
{ foo :: Int; foo = 3 }
module Main (main) where
{ import MyMod (foo); main :: IO (); main = print foo }
The Haskell98 report doesn't say anything about how modules are expected to be laid out in files, so I had assumed it would work. The error is
parse error on input `module'
(except if Main comes before MyMod
, and --make is used with ghc, we get
Could not find module `MyMod':
Use -v to see a list of the files searched for.
even though MyMod
is clearly (to a human) in that very file.)
It took me a long time to figure out what was wrong and what I had to do. Admittedly I'm only slightly interested in GHC implementing support to allow this, since if multiple files are involved at all it causes module-finding trouble (obviously to me now); mostly I just want a good error message, maybe something like "Each file must contain exactly one module. Any module intended to be imported must be in an appropriately named file, e.g. module Module.Name' goes in
Module/Name.hs'."
( This happened to me a long time ago... but I was reminded by #2427 )
Trac metadata
Trac field | Value |
---|---|
Version | 6.8.2 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | Unknown |
Architecture | Unknown |