Combine GREs when combining in mkImportOccEnv
In GHC.Rename.Names.mkImportOccEnv
, we sometimes discard one import
item in favour of another, as explained in Note [Dealing with imports]
in GHC.Rename.Names
. However, this can cause us to lose track of
important parent information.
Consider for example #24084 (closed):
module M1 where { class C a where { type T a } }
module M2 ( module M1 ) where { import M1 }
module M3 where { import M2 ( C, T ); instance C () where T () = () }
When processing the import list of M3
, we start off (for reasons that
are not relevant right now) with two Avail
s attached to T
, namely
C(C, T)
and T(T)
. We combine them in the combine
function of
mkImportOccEnv
; as described in Note [Dealing with imports] we discard
C(C, T)
in favour of T(T)
. However, in doing so, we must not
discard the information want that C
is the parent of T
. Indeed,
losing track of this information can cause errors when importing,
as we could get an error of the form
‘T’ is not a (visible) associated type of class ‘C’
We fix this by combining the two GREs for T
using plusGRE
.