diff options
author | Ryan Scott <ryan.gl.scott@gmail.com> | 2021-04-29 17:35:47 -0400 |
---|---|---|
committer | Ryan Scott <ryan.gl.scott@gmail.com> | 2021-04-30 11:48:19 -0400 |
commit | 89bf726c87483fab493fbef57a539f51585820a3 (patch) | |
tree | 95d817824931ba80030e1a4e51d2729419191a73 /compiler/GHC/Tc/Module.hs | |
parent | 2d2985a79eec3d6ae9aee96b264c97c2b158f196 (diff) | |
download | haskell-wip/T19738.tar.gz |
Bring tcTyConScopedTyVars into scope in tcClassDecl2wip/T19738
It is possible that the type variables bound by a class header will map to
something different in the typechecker in the presence of
`StandaloneKindSignatures`. `tcClassDecl2` was not aware of this, however,
leading to #19738. To fix it, in `tcTyClDecls` we map each class `TcTyCon` to
its `tcTyConScopedTyVars` as a `ClassScopedTVEnv`. We then plumb that
`ClassScopedTVEnv` to `tcClassDecl2` where it can be used.
Fixes #19738.
Diffstat (limited to 'compiler/GHC/Tc/Module.hs')
-rw-r--r-- | compiler/GHC/Tc/Module.hs | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/compiler/GHC/Tc/Module.hs b/compiler/GHC/Tc/Module.hs index 0511e1e268..fc330061e8 100644 --- a/compiler/GHC/Tc/Module.hs +++ b/compiler/GHC/Tc/Module.hs @@ -75,6 +75,7 @@ import GHC.Tc.Gen.Default import GHC.Tc.Utils.Env import GHC.Tc.Gen.Rule import GHC.Tc.Gen.Foreign +import GHC.Tc.TyCl.Class ( ClassScopedTVEnv ) import GHC.Tc.TyCl.Instance import GHC.Tc.Utils.TcMType import GHC.Tc.Utils.TcType @@ -699,7 +700,7 @@ tcRnHsBootDecls hsc_src decls -- Typecheck type/class/instance decls ; traceTc "Tc2 (boot)" empty - ; (tcg_env, inst_infos, _deriv_binds) + ; (tcg_env, inst_infos, _deriv_binds, _class_scoped_tv_env) <- tcTyClsInstDecls tycl_decls deriv_decls val_binds ; setGblEnv tcg_env $ do { @@ -1456,7 +1457,8 @@ tcTopSrcDecls (HsGroup { hs_tyclds = tycl_decls, -- Source-language instances, including derivings, -- and import the supporting declarations traceTc "Tc3" empty ; - (tcg_env, inst_infos, XValBindsLR (NValBinds deriv_binds deriv_sigs)) + (tcg_env, inst_infos, class_scoped_tv_env, + XValBindsLR (NValBinds deriv_binds deriv_sigs)) <- tcTyClsInstDecls tycl_decls deriv_decls val_binds ; setGblEnv tcg_env $ do { @@ -1497,7 +1499,8 @@ tcTopSrcDecls (HsGroup { hs_tyclds = tycl_decls, -- Second pass over class and instance declarations, -- now using the kind-checked decls traceTc "Tc6" empty ; - inst_binds <- tcInstDecls2 (tyClGroupTyClDecls tycl_decls) inst_infos ; + inst_binds <- tcInstDecls2 (tyClGroupTyClDecls tycl_decls) + inst_infos class_scoped_tv_env ; -- Foreign exports traceTc "Tc7" empty ; @@ -1733,13 +1736,14 @@ tcTyClsInstDecls :: [TyClGroup GhcRn] [InstInfo GhcRn], -- Source-code instance decls to -- process; contains all dfuns for -- this module + ClassScopedTVEnv, -- Class scoped type variables HsValBinds GhcRn) -- Supporting bindings for derived -- instances tcTyClsInstDecls tycl_decls deriv_decls binds = tcAddDataFamConPlaceholders (tycl_decls >>= group_instds) $ tcAddPatSynPlaceholders (getPatSynBinds binds) $ - do { (tcg_env, inst_info, deriv_info) + do { (tcg_env, inst_info, deriv_info, class_scoped_tv_env) <- tcTyAndClassDecls tycl_decls ; ; setGblEnv tcg_env $ do { -- With the @TyClDecl@s and @InstDecl@s checked we're ready to @@ -1753,7 +1757,8 @@ tcTyClsInstDecls tycl_decls deriv_decls binds <- tcInstDeclsDeriv deriv_info deriv_decls ; setGblEnv tcg_env' $ do { failIfErrsM - ; pure (tcg_env', inst_info' ++ inst_info, val_binds) + ; pure ( tcg_env', inst_info' ++ inst_info + , class_scoped_tv_env, val_binds ) }}} {- ********************************************************************* |