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: 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`. Fixes #24084
Showing
- compiler/GHC/Rename/Env.hs 19 additions, 16 deletionscompiler/GHC/Rename/Env.hs
- compiler/GHC/Rename/Names.hs 49 additions, 10 deletionscompiler/GHC/Rename/Names.hs
- compiler/GHC/Types/Avail.hs 1 addition, 1 deletioncompiler/GHC/Types/Avail.hs
- compiler/GHC/Types/Name/Reader.hs 23 additions, 0 deletionscompiler/GHC/Types/Name/Reader.hs
- testsuite/tests/rename/should_compile/T24084.hs 11 additions, 0 deletionstestsuite/tests/rename/should_compile/T24084.hs
- testsuite/tests/rename/should_compile/T24084_A.hs 8 additions, 0 deletionstestsuite/tests/rename/should_compile/T24084_A.hs
- testsuite/tests/rename/should_compile/T24084_B.hs 7 additions, 0 deletionstestsuite/tests/rename/should_compile/T24084_B.hs
- testsuite/tests/rename/should_compile/all.T 1 addition, 0 deletionstestsuite/tests/rename/should_compile/all.T
Loading
Please register or sign in to comment