Commit 343cb32d authored by mrkgnao's avatar mrkgnao Committed by Ben Gamari
Browse files

Fix incorrect ambiguity error on identically-named data constructors

Given multiple in-scope constructors with the same name, say `A`, and a
function of type `A -> Int`, say, the compiler reports both a "type `A`
is not in scope" and (incorrectly) an ambiguity error. The latter
shouldn't be there if `DataKinds` isn't enabled.

This issue was recommended to me by @mpickering

 as a suitable first
task, and the fix was also outlined in the original Trac ticket. It
involved a simple reordering of the steps taken in `lookup_demoted` in
`RnEnv.hs`. The fix is to make the `DataKinds` check happen earlier,
ensuring that the ambiguity check doesn't happen at all if we know the
constructors couldn't have been promoted.
Signed-off-by: mrkgnao's avatarSoham Chowdhury <chow.soham@gmail.com>

Reviewers: mpickering, austin, bgamari

Reviewed By: mpickering, bgamari

Subscribers: rwbarton, thomie

GHC Trac Issues: #13568

Differential Revision: https://phabricator.haskell.org/D3547

(cherry picked from commit 1381c142)
parent 56a4863b
......@@ -723,16 +723,17 @@ lookup_demoted rdr_name dflags
| Just demoted_rdr <- demoteRdrName rdr_name
-- Maybe it's the name of a *data* constructor
= do { data_kinds <- xoptM LangExt.DataKinds
; mb_demoted_name <- lookupOccRn_maybe demoted_rdr
; case mb_demoted_name of
Nothing -> unboundNameX WL_Any rdr_name star_info
Just demoted_name
| data_kinds ->
do { whenWOptM Opt_WarnUntickedPromotedConstructors $
addWarn (Reason Opt_WarnUntickedPromotedConstructors)
(untickedPromConstrWarn demoted_name)
; return demoted_name }
| otherwise -> unboundNameX WL_Any rdr_name suggest_dk }
; if data_kinds
then do { mb_demoted_name <- lookupOccRn_maybe demoted_rdr
; case mb_demoted_name of
Nothing -> unboundNameX WL_Any rdr_name star_info
Just demoted_name ->
do { whenWOptM Opt_WarnUntickedPromotedConstructors $
addWarn
(Reason Opt_WarnUntickedPromotedConstructors)
(untickedPromConstrWarn demoted_name)
; return demoted_name } }
else unboundNameX WL_Any rdr_name suggest_dk }
| otherwise
= reportUnboundName rdr_name
......
mod122.hs:5:6: Not in scope: type constructor or class ‘C’
mod122.hs:5:6: error:
Not in scope: type constructor or class ‘C’
A data constructor of that name is in scope; did you mean DataKinds?
mod123.hs:5:6: Not in scope: type constructor or class ‘T’
mod123.hs:5:6: error:
Not in scope: type constructor or class ‘T’
A data constructor of that name is in scope; did you mean DataKinds?
mod124.hs:6:6: error:
Not in scope: type constructor or class ‘T’
A data constructor of that name is in scope; did you mean DataKinds?
Perhaps you want to remove ‘T’ from the explicit hiding list
in the import of ‘Mod124_A’ (mod124.hs:4:1-26).
mod127.hs:6:6: error:
Not in scope: type constructor or class ‘T’
A data constructor of that name is in scope; did you mean DataKinds?
Perhaps you want to remove ‘T’ from the explicit hiding list
in the import of ‘Mod127_A’ (mod127.hs:4:1-26).
mod29.hs:6:12: error:
Not in scope: type constructor or class ‘Char’
A data constructor of that name is in scope; did you mean DataKinds?
Perhaps you want to add ‘Char’ to the import list in the import of
‘Prelude’ (mod29.hs:5:1-19).
mod50.hs:3:22: Not in scope: type constructor or class ‘Foo’
mod50.hs:3:22: error:
Not in scope: type constructor or class ‘Foo’
A data constructor of that name is in scope; did you mean DataKinds?
......@@ -16,3 +16,4 @@ readFail001.hs:107:42: error: Not in scope: data constructor ‘Bar’
readFail001.hs:112:23: error:
Not in scope: type constructor or class ‘Foo’
A data constructor of that name is in scope; did you mean DataKinds?
B.hs:4:6: Not in scope: type constructor or class ‘Class’
B.hs:4:6: error:
Not in scope: type constructor or class ‘Class’
A data constructor of that name is in scope; did you mean DataKinds?
module T13568 where
import T13568a
data S = A
foo :: A -> ()
foo = undefined
T13568.hs:7:8: error:
Not in scope: type constructor or class ‘A’
A data constructor of that name is in scope; did you mean DataKinds?
T1595a.hs:3:20: Not in scope: type constructor or class ‘Tpyo’
T1595a.hs:3:20: error:
Not in scope: type constructor or class ‘Tpyo’
A data constructor of that name is in scope; did you mean DataKinds?
T5745.hs:5:6: Not in scope: type constructor or class ‘T’
T5745.hs:5:6: error:
Not in scope: type constructor or class ‘T’
A data constructor of that name is in scope; did you mean DataKinds?
......@@ -125,3 +125,4 @@ test('T12681', normal, multimod_compile_fail, ['T12681','-v0'])
test('T12686', normal, compile_fail, [''])
test('T11592', normal, compile_fail, [''])
test('T12879', normal, compile_fail, [''])
test('T13568', normal, multimod_compile_fail, ['T13568','-v0'])
T1595.hs:8:15:
T1595.hs:8:15: error:
Not in scope: type constructor or class ‘DoesNotExist’
A data constructor of that name is in scope; did you mean DataKinds?
T1595.hs:13:22:
T1595.hs:13:22: error:
Not in scope: type constructor or class ‘DoesNotExist’
A data constructor of that name is in scope; did you mean DataKinds?
tcfail048.hs:3:8: Not in scope: type constructor or class ‘B’
tcfail048.hs:3:8: error:
Not in scope: type constructor or class ‘B’
A data constructor of that name is in scope; did you mean DataKinds?
tcfail053.hs:3:12: Not in scope: type constructor or class ‘A’
tcfail053.hs:3:12: error:
Not in scope: type constructor or class ‘A’
A data constructor of that name is in scope; did you mean DataKinds?
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment