Use tcSplitForAllInvisTyVars (not tcSplitForAllTyVars) in more places
The use of `tcSplitForAllTyVars` in `tcDataFamInstHeader` was the immediate cause of #18939, and replacing it with a new `tcSplitForAllInvisTyVars` function (which behaves like `tcSplitForAllTyVars` but only splits invisible type variables) fixes the issue. However, this led me to realize that _most_ uses of `tcSplitForAllTyVars` in GHC really ought to be `tcSplitForAllInvisTyVars` instead. While I was in town, I opted to replace most uses of `tcSplitForAllTys` with `tcSplitForAllTysInvis` to reduce the likelihood of such bugs in the future. I say "most uses" above since there is one notable place where we _do_ want to use `tcSplitForAllTyVars`: in `GHC.Tc.Validity.forAllTyErr`, which produces the "`Illegal polymorphic type`" error message if you try to use a higher-rank `forall` without having `RankNTypes` enabled. Here, we really do want to split all `forall`s, not just invisible ones, or we run the risk of giving an inaccurate error message in the newly added `T18939_Fail` test case. I debated at some length whether I wanted to name the new function `tcSplitForAllInvisTyVars` or `tcSplitForAllTyVarsInvisible`, but in the end, I decided that I liked the former better. For consistency's sake, I opted to rename the existing `splitPiTysInvisible` and `splitPiTysInvisibleN` functions to `splitInvisPiTys` and `splitPiTysInvisN`, respectively, so that they use the same naming convention. As a consequence, this ended up requiring a `haddock` submodule bump. Fixes #18939.
Showing
- compiler/GHC/Core/Type.hs 11 additions, 11 deletionscompiler/GHC/Core/Type.hs
- compiler/GHC/HsToCore/Foreign/Decl.hs 2 additions, 2 deletionscompiler/GHC/HsToCore/Foreign/Decl.hs
- compiler/GHC/Runtime/Heap/Inspect.hs 1 addition, 1 deletioncompiler/GHC/Runtime/Heap/Inspect.hs
- compiler/GHC/Tc/Gen/HsType.hs 2 additions, 2 deletionscompiler/GHC/Tc/Gen/HsType.hs
- compiler/GHC/Tc/TyCl/Instance.hs 1 addition, 1 deletioncompiler/GHC/Tc/TyCl/Instance.hs
- compiler/GHC/Tc/Utils/Backpack.hs 2 additions, 2 deletionscompiler/GHC/Tc/Utils/Backpack.hs
- compiler/GHC/Tc/Utils/Instantiate.hs 1 addition, 1 deletioncompiler/GHC/Tc/Utils/Instantiate.hs
- compiler/GHC/Tc/Utils/TcType.hs 15 additions, 8 deletionscompiler/GHC/Tc/Utils/TcType.hs
- compiler/GHC/Tc/Validity.hs 1 addition, 1 deletioncompiler/GHC/Tc/Validity.hs
- testsuite/tests/typecheck/should_compile/T18939_Compile.hs 11 additions, 0 deletionstestsuite/tests/typecheck/should_compile/T18939_Compile.hs
- testsuite/tests/typecheck/should_compile/all.T 1 addition, 0 deletionstestsuite/tests/typecheck/should_compile/all.T
- testsuite/tests/typecheck/should_fail/T18939_Fail.hs 5 additions, 0 deletionstestsuite/tests/typecheck/should_fail/T18939_Fail.hs
- testsuite/tests/typecheck/should_fail/T18939_Fail.stderr 5 additions, 0 deletionstestsuite/tests/typecheck/should_fail/T18939_Fail.stderr
- testsuite/tests/typecheck/should_fail/all.T 1 addition, 0 deletionstestsuite/tests/typecheck/should_fail/all.T
- utils/haddock 1 addition, 1 deletionutils/haddock
Please register or sign in to comment