summaryrefslogtreecommitdiff
path: root/compiler/types/Type.hs
diff options
context:
space:
mode:
authorRyan Scott <ryan.gl.scott@gmail.com>2019-04-01 20:36:31 -0400
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-04-04 04:29:29 -0400
commit25c02ea172ef1dad2d12d8baff6ce57a68bf4127 (patch)
tree6b1a044b85ecb82c2b7f1edaece878aec6a9098b /compiler/types/Type.hs
parent75abaaead796415cf2b5da610f4b3ee75b9d7759 (diff)
downloadhaskell-25c02ea172ef1dad2d12d8baff6ce57a68bf4127.tar.gz
Fix #16518 with some more kind-splitting smarts
This patch corrects two simple oversights that led to #16518: 1. `HsUtils.typeToLHsType` was taking visibility into account in the `TyConApp` case, but not the `AppTy` case. I've factored out the visibility-related logic into its own `go_app` function and now invoke `go_app` from both the `TyConApp` and `AppTy` cases. 2. `Type.fun_kind_arg_flags` did not properly split kinds with nested `forall`s, such as `(forall k. k -> Type) -> (forall k. k -> Type)`. This was simply because `fun_kind_arg_flags`'s `FunTy` case always bailed out and assumed all subsequent arguments were `Required`, which clearly isn't the case for nested `forall`s. I tweaked the `FunTy` case to recur on the result kind.
Diffstat (limited to 'compiler/types/Type.hs')
-rw-r--r--compiler/types/Type.hs15
1 files changed, 15 insertions, 0 deletions
diff --git a/compiler/types/Type.hs b/compiler/types/Type.hs
index 4426148967..c144d3e8f1 100644
--- a/compiler/types/Type.hs
+++ b/compiler/types/Type.hs
@@ -1698,6 +1698,21 @@ fun_kind_arg_flags = go emptyTCvSubst
subst' = extendTvSubst subst tv arg_ty
go subst (TyVarTy tv) arg_tys
| Just ki <- lookupTyVar subst tv = go subst ki arg_tys
+ -- This FunTy case is important to handle kinds with nested foralls, such
+ -- as this kind (inspired by #16518):
+ --
+ -- forall {k1} k2. k1 -> k2 -> forall k3. k3 -> Type
+ --
+ -- Here, we want to get the following ArgFlags:
+ --
+ -- [Inferred, Specified, Required, Required, Specified, Required]
+ -- forall {k1}. forall k2. k1 -> k2 -> forall k3. k3 -> Type
+ go subst (FunTy{ft_af = af, ft_res = res_ki}) (_:arg_tys)
+ = argf : go subst res_ki arg_tys
+ where
+ argf = case af of
+ VisArg -> Required
+ InvisArg -> Inferred
go _ _ arg_tys = map (const Required) arg_tys
-- something is ill-kinded. But this can happen
-- when printing errors. Assume everything is Required.