From ab618309069bb47645f33cd1b198ace46e27abb9 Mon Sep 17 00:00:00 2001 From: Vladislav Zavialov Date: Sun, 18 Oct 2020 15:24:31 +0300 Subject: Export (~) from Data.Type.Equality (#18862) * Users can define their own (~) type operator * Haddock can display documentation for the built-in (~) * New transitional warnings implemented: -Wtype-equality-out-of-scope -Wtype-equality-requires-operators Updates the haddock submodule. --- compiler/GHC/Rename/Env.hs | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'compiler/GHC/Rename/Env.hs') diff --git a/compiler/GHC/Rename/Env.hs b/compiler/GHC/Rename/Env.hs index cd40ab100a..3525c71f1b 100644 --- a/compiler/GHC/Rename/Env.hs +++ b/compiler/GHC/Rename/Env.hs @@ -1047,7 +1047,24 @@ lookupTypeOccRn rdr_name = do { mb_name <- lookupOccRn_maybe rdr_name ; case mb_name of Just name -> return name - Nothing -> lookup_demoted rdr_name } + Nothing -> + if occName rdr_name == occName eqTyCon_RDR -- See Note [eqTyCon (~) compatibility fallback] + then eqTyConName <$ addDiagnostic TcRnTypeEqualityOutOfScope + else lookup_demoted rdr_name } + +{- Note [eqTyCon (~) compatibility fallback] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Before GHC Proposal #371, the (~) type operator used in type equality +constraints (a~b) was considered built-in syntax. + +This had two implications: + +1. Users could use it without importing it from Data.Type.Equality or Prelude. +2. TypeOperators were not required to use it (it was guarded behind TypeFamilies/GADTs instead) + +To ease migration and minimize breakage, we continue to support those usages +but emit appropriate warnings. +-} lookup_demoted :: RdrName -> RnM Name lookup_demoted rdr_name @@ -1919,13 +1936,7 @@ dataTcOccs rdr_name = [rdr_name] where occ = rdrNameOcc rdr_name - rdr_name_tc = - case rdr_name of - -- The (~) type operator is always in scope, so we need a special case - -- for it here, or else :info (~) fails in GHCi. - -- See Note [eqTyCon (~) is built-in syntax] - Unqual occ | occNameFS occ == fsLit "~" -> eqTyCon_RDR - _ -> setRdrNameSpace rdr_name tcName + rdr_name_tc = setRdrNameSpace rdr_name tcName {- Note [dataTcOccs and Exact Names] -- cgit v1.2.1