Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
GHC
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Artem Pyanykh
GHC
Commits
2762f94d
Commit
2762f94d
authored
Mar 02, 2019
by
Roland Senn
Committed by
Marge Bot
Mar 08, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #13839: GHCi warnings do not respect the default module header
parent
224a6b86
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
82 additions
and
4 deletions
+82
-4
compiler/typecheck/TcRnExports.hs
compiler/typecheck/TcRnExports.hs
+34
-4
testsuite/tests/rename/should_compile/T13839.script
testsuite/tests/rename/should_compile/T13839.script
+4
-0
testsuite/tests/rename/should_compile/T13839.stdout
testsuite/tests/rename/should_compile/T13839.stdout
+5
-0
testsuite/tests/rename/should_compile/T13839a.hs
testsuite/tests/rename/should_compile/T13839a.hs
+10
-0
testsuite/tests/rename/should_compile/T13839a.stderr
testsuite/tests/rename/should_compile/T13839a.stderr
+3
-0
testsuite/tests/rename/should_compile/T13839b.hs
testsuite/tests/rename/should_compile/T13839b.hs
+10
-0
testsuite/tests/rename/should_compile/all.T
testsuite/tests/rename/should_compile/all.T
+2
-0
testsuite/tests/rename/should_fail/T13839b.hs
testsuite/tests/rename/should_fail/T13839b.hs
+10
-0
testsuite/tests/rename/should_fail/T13839b.stderr
testsuite/tests/rename/should_fail/T13839b.stderr
+3
-0
testsuite/tests/rename/should_fail/all.T
testsuite/tests/rename/should_fail/all.T
+1
-0
No files found.
compiler/typecheck/TcRnExports.hs
View file @
2762f94d
...
...
@@ -170,22 +170,24 @@ tcRnExports explicit_mod exports
-- list, to avoid bleating about re-exporting a deprecated
-- thing (especially via 'module Foo' export item)
do
{
-- In interactive mode, we behave as if he had
-- written "module Main where ..."
;
dflags
<-
getDynFlags
;
let
is_main_mod
=
mainModIs
dflags
==
this_mod
;
let
default_main
=
case
mainFunIs
dflags
of
Just
main_fun
|
is_main_mod
->
mkUnqual
varName
(
fsLit
main_fun
)
_
->
main_RDR_Unqual
;
has_main
<-
lookupGlobalOccRn_maybe
default_main
>>=
return
.
isJust
-- If the module has no explicit header, and it has a main function,
-- then we add a header like "module Main(main) where ..." (#13839)
-- See Note [Modules without a module header]
;
let
real_exports
|
explicit_mod
=
exports
|
ghcLink
dflags
==
LinkInMemory
=
Nothing
|
otherwise
|
has_main
=
Just
(
noLoc
[
noLoc
(
IEVar
noExt
(
noLoc
(
IEName
$
noLoc
default_main
)))])
-- ToDo: the 'noLoc' here is unhelpful if 'main'
-- turns out to be out of scope
|
otherwise
=
Nothing
;
let
do_it
=
exports_from_avail
real_exports
rdr_env
imports
this_mod
;
(
rn_exports
,
final_avails
)
...
...
@@ -436,6 +438,34 @@ isDoc _ = False
-- Renaming and typechecking of exports happens after everything else has
-- been typechecked.
{-
Note [Modules without a module header]
--------------------------------------------------
The Haskell 2010 report says in 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’.
For modules without a module header, this is implemented the
following way:
If the module has a main function:
Then create a module header and export the main function.
This has the effect to mark the main function and all top level
functions called directly or indirectly via main as 'used',
and later on, unused top-level functions can be reported correctly.
There is no distinction between GHC and GHCi.
If the module has NO main function:
Then export all top-level functions. This marks all top level
functions as 'used'.
In GHCi this has the effect, that we don't get any 'non-used' warnings.
In GHC, however, the 'has-main-module' check in the module
compiler/typecheck/TcRnDriver (functions checkMain / check-main) fires,
and we get the error:
The IO action ‘main’ is not defined in module ‘Main’
-}
-- Renaming exports lists is a minefield. Five different things can appear in
...
...
testsuite/tests/rename/should_compile/T13839.script
0 → 100644
View file @
2762f94d
:l T13839a.hs
:t nonUsed
:l T13839b.hs
:t nonUsed
testsuite/tests/rename/should_compile/T13839.stdout
0 → 100644
View file @
2762f94d
T13839a.hs:10:1: warning: [-Wunused-top-binds (in -Wextra, -Wunused-binds)]
Defined but not used: ‘nonUsed’
nonUsed :: ()
nonUsed :: ()
testsuite/tests/rename/should_compile/T13839a.hs
0 → 100644
View file @
2762f94d
{-# OPTIONS_GHC -Wall #-}
main
::
IO
()
main
=
putStrLn
used
used
::
String
used
=
"T13839"
nonUsed
::
()
nonUsed
=
()
testsuite/tests/rename/should_compile/T13839a.stderr
0 → 100644
View file @
2762f94d
T13839a.hs:10:1: warning: [-Wunused-top-binds (in -Wextra, -Wunused-binds)]
Defined but not used: ‘nonUsed’
testsuite/tests/rename/should_compile/T13839b.hs
0 → 100644
View file @
2762f94d
{-# OPTIONS_GHC -Wall #-}
nomain
::
IO
()
nomain
=
putStrLn
used
used
::
String
used
=
"T13839"
nonUsed
::
()
nonUsed
=
()
testsuite/tests/rename/should_compile/all.T
View file @
2762f94d
...
...
@@ -155,6 +155,8 @@ test('T12597', normal, compile, [''])
test
('
T12548
',
normal
,
compile
,
[''])
test
('
T13132
',
normal
,
compile
,
[''])
test
('
T13646
',
normal
,
compile
,
[''])
test
('
T13839
',
combined_output
,
ghci_script
,
['
T13839.script
'])
test
('
T13839a
',
normal
,
compile
,
[''])
test
('
LookupSub
',
[]
,
multimod_compile
,
['
LookupSub
',
'
-v0
'])
test
('
T14881
',
[]
,
multimod_compile
,
['
T14881
',
'
-W
'])
test
('
T14487
',
[]
,
multimod_compile
,
['
T14487
',
'
-v0
'])
...
...
testsuite/tests/rename/should_fail/T13839b.hs
0 → 100644
View file @
2762f94d
{-# OPTIONS_GHC -Wall #-}
nomain
::
IO
()
nomain
=
putStrLn
used
used
::
String
used
=
"T13839"
nonUsed
::
()
nonUsed
=
()
testsuite/tests/rename/should_fail/T13839b.stderr
0 → 100644
View file @
2762f94d
T13839b.hs:1:1: error:
The IO action ‘main’ is not defined in module ‘Main’
testsuite/tests/rename/should_fail/all.T
View file @
2762f94d
...
...
@@ -126,6 +126,7 @@ test('T11592', normal, compile_fail, [''])
test
('
T12879
',
normal
,
compile_fail
,
[''])
test
('
T13644
',
normal
,
multimod_compile_fail
,
['
T13644
','
-v0
'])
test
('
T13568
',
normal
,
multimod_compile_fail
,
['
T13568
','
-v0
'])
test
('
T13839b
',
normal
,
compile_fail
,
[''])
test
('
T13947
',
normal
,
compile_fail
,
[''])
test
('
T13847
',
normal
,
multimod_compile_fail
,
['
T13847
','
-v0
'])
test
('
T14225
',
normal
,
ghci_script
,
['
T14225.script
'])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment