
#13839: GHCi warnings do not respect the default module header -------------------------------------+------------------------------------- Reporter: Feuerbach | Owner: RolandSenn Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RolandSenn): Testing my patch, I found some behaviour, that may be unexpected / annoying for ghci users, specially beginners: Consider a module Foo.hs without a `main` function and without a module header: {{{ nomain :: IO () nomain = putStrLn usedVar usedVar :: String usedVar = "T13839" }}} Compiling with GHC 8.6 (`ghc -Wall Foo.hs`) gives: {{{ [1 of 1] Compiling Main ( Foo.hs, Foo.o ) Foo.hs:1:1: error: The IO action ‘main’ is not defined in module ‘Main’ }}} Loading into GHCi ''just works'': {{{ ghci -Wall Foo.hs GHCi, version 8.6.2: http://www.haskell.org/ghc/ :? for help [1 of 1] Compiling Main ( Foo.hs, interpreted ) Ok, one module loaded. *Main> }}} Now with the new warnings I get: {{{ GHCi, version 8.7.20181207: http://www.haskell.org/ghc/ :? for help [1 of 1] Compiling Main ( Foo.hs, interpreted ) Foo.hs:2:1: warning: [-Wunused-top-binds] Defined but not used: ‘nomain’ Foo.hs:5:1: warning: [-Wunused-top-binds] Defined but not used: ‘usedVar’ Ok, one module loaded. *Main> }}} We get the same warnings with GHC-8.6, after adding a `main` function. **In a module without a module header and without a `main` function GHCi will report ALL top level names as unused! ** Therefore I propose to issue the requested warnings in GHCi only, if there is a `main` function available! @Feuerbach: Do you agree? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13839#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler