[GHC] #13839: GHC warnings do not respect the default module header

An abbreviated form of module, consisting only of the module body, is
#13839: GHC warnings do not respect the default module header -------------------------------------+------------------------------------- Reporter: Feuerbach | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- If I compile this program with `-Wall`, I get no warnings: {{{#!hs type T = Int main :: IO () main = return () }}} If I add a module header: {{{#!hs module Main(main) where type T = Int main :: IO () main = return () }}} I now get a warning: {{{ ghcbug2.hs:3:1: warning: [-Wunused-top-binds] Defined but not used: type constructor or class ‘T’ }}} Yet, according to Haskell2010 (section 5.1): permitted. If this is used, the header is assumed to be ‘module Main(main) where’. Therefore, the right behaviour should be to print a warning in the first case as well. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13839 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13839: GHC warnings do not respect the default module header -------------------------------------+------------------------------------- Reporter: Feuerbach | Owner: (none) Type: bug | Status: infoneeded 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: | -------------------------------------+------------------------------------- Changes (by RolandSenn): * cc: RolandSenn (added) * status: new => infoneeded Comment: @Feuerbach: Can you still reproduce this? With ''cat T13869.hs'' {{{#!hs type T = Int main :: IO () main = return () }}} ''ghc --version && ghc -Wall T13893.hs'' I get {{{ The Glorious Glasgow Haskell Compilation System, version 8.6.2 [1 of 1] Compiling Main ( T13893.hs, T13893.o ) T13893.hs:1:1: warning: [-Wunused-top-binds] Defined but not used: type constructor or class ‘T’ | 1 | type T = Int | ^^^^^^^^^^^^ Linking T13893 ... }}} Even with GHC 8.0.1 I'm unable to reproduce your problem! How did you compile your program? What's your OS? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13839#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13839: GHC warnings do not respect the default module header -------------------------------------+------------------------------------- Reporter: Feuerbach | Owner: (none) Type: bug | Status: infoneeded 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 Feuerbach): You are right, I cannot reproduce this by compiling the program either. However, I can reproduce this by loading it into ghci, with both 8.0.1 and 8.6.2. I'll update the description to reflect this. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13839#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13839: GHC warnings do not respect the default module header -------------------------------------+------------------------------------- Reporter: Feuerbach | Owner: (none) 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: | -------------------------------------+------------------------------------- Changes (by Feuerbach): * status: infoneeded => new Old description:
If I compile this program with `-Wall`, I get no warnings:
{{{#!hs type T = Int
main :: IO () main = return () }}}
If I add a module header:
{{{#!hs module Main(main) where
type T = Int
main :: IO () main = return () }}}
I now get a warning:
{{{ ghcbug2.hs:3:1: warning: [-Wunused-top-binds] Defined but not used: type constructor or class ‘T’ }}}
Yet, according to Haskell2010 (section 5.1):
An abbreviated form of module, consisting only of the module body, is permitted. If this is used, the header is assumed to be ‘module Main(main) where’.
Therefore, the right behaviour should be to print a warning in the first case as well.
An abbreviated form of module, consisting only of the module body, is
New description: If I load this program in ghci with `-Wall`, I get no warnings: {{{#!hs type T = Int main :: IO () main = return () }}} If I add a module header: {{{#!hs module Main(main) where type T = Int main :: IO () main = return () }}} I now get a warning: {{{ ghcbug2.hs:3:1: warning: [-Wunused-top-binds] Defined but not used: type constructor or class ‘T’ }}} Yet, according to Haskell2010 (section 5.1): permitted. If this is used, the header is assumed to be ‘module Main(main) where’. Therefore, the right behaviour should be to print a warning in the first case as well. If I compile the program instead of loading it in ghci, I correctly get the warning in both cases. -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13839#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13839: GHC 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: | -------------------------------------+------------------------------------- Changes (by RolandSenn): * owner: (none) => RolandSenn -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13839#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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

#13839: GHCi warnings do not respect the default module header -------------------------------------+------------------------------------- Reporter: Feuerbach | Owner: RolandSenn Type: bug | Status: patch 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: make test | TEST=T13839 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D5449 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RolandSenn): * testcase: => make test TEST=T13839 * status: new => patch * differential: => Phab:D5449 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13839#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13839: GHCi warnings do not respect the default module header -------------------------------------+------------------------------------- Reporter: Feuerbach | Owner: RolandSenn Type: bug | Status: patch 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: make test | TEST=T13839 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D5449 Wiki Page: | -------------------------------------+------------------------------------- Comment (by osa1): Roland, can you move the patch to Gitlab? We're much more active there and I think people will miss the patch or forget about it if it stays on Phabricator. We should get some feedback on the proposed behavior in comment:5 vs. the current behavior before reviewing. Personally I don't find the current behavior confusing, but maybe because I'm accustomed to it already. Not sure what's a good platform for this kind of discussion though.. (maybe haskell-cafe?) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13839#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13839: GHCi warnings do not respect the default module header -------------------------------------+------------------------------------- Reporter: Feuerbach | Owner: RolandSenn Type: bug | Status: patch 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: make test | TEST=T13839 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D5449 Wiki Page: | -------------------------------------+------------------------------------- Comment (by RolandSenn): @osa1 No Problem! I‘ll move the Patch to Gitlab next week, after my ski holidays. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13839#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13839: GHCi warnings do not respect the default module header -------------------------------------+------------------------------------- Reporter: Feuerbach | Owner: RolandSenn Type: bug | Status: patch 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: make test | TEST=T13839 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | https://gitlab.haskell.org/ghc/ghc/merge_requests/215 -------------------------------------+------------------------------------- Changes (by RolandSenn): * differential: Phab:D5449 => https://gitlab.haskell.org/ghc/ghc/merge_requests/215 Comment: @osa1 Finally I moved the patch from Phabricator to Gitlab. Sorry for the delay. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13839#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13839: GHCi warnings do not respect the default module header -------------------------------------+------------------------------------- Reporter: Feuerbach | Owner: RolandSenn Type: bug | Status: patch 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: make test | TEST=T13839 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | https://gitlab.haskell.org/ghc/ghc/merge_requests/292 -------------------------------------+------------------------------------- Changes (by RolandSenn): * differential: https://gitlab.haskell.org/ghc/ghc/merge_requests/215 => https://gitlab.haskell.org/ghc/ghc/merge_requests/292 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13839#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13839: GHCi warnings do not respect the default module header -------------------------------------+------------------------------------- Reporter: Feuerbach | Owner: RolandSenn Type: bug | Status: patch Priority: normal | Milestone: 8.10.1 Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: make test | TESTS="T13839 T13839a T13839b" Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | https://gitlab.haskell.org/ghc/ghc/merge_requests/292 -------------------------------------+------------------------------------- Changes (by RolandSenn): * testcase: make test TEST=T13839 => make test TESTS="T13839 T13839a T13839b" * milestone: => 8.10.1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13839#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13839: GHCi warnings do not respect the default module header
-------------------------------------+-------------------------------------
Reporter: Feuerbach | Owner: RolandSenn
Type: bug | Status: patch
Priority: normal | Milestone: 8.10.1
Component: Compiler | Version: 8.0.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case: make test
| TESTS="T13839 T13839a T13839b"
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: | https://gitlab.haskell.org/ghc/ghc/merge_requests/292
-------------------------------------+-------------------------------------
Comment (by Marge Bot
participants (1)
-
GHC