diff options
| author | Simon Peyton Jones <simonpj@microsoft.com> | 2018-11-06 09:10:30 +0000 |
|---|---|---|
| committer | Simon Peyton Jones <simonpj@microsoft.com> | 2018-11-15 09:05:23 +0000 |
| commit | 0ce66be953becf7c9de3cbea406953306b4db3b1 (patch) | |
| tree | 360a8e3fbe935b42941850c9785795811ffe7ad9 /compiler | |
| parent | fe0576426d3ef07d7743c65e34c8b04ce0616426 (diff) | |
| download | haskell-0ce66be953becf7c9de3cbea406953306b4db3b1.tar.gz | |
Comments adding to the fix for Trac #15859
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/typecheck/TcExpr.hs | 28 | ||||
| -rw-r--r-- | compiler/types/TyCoRep.hs | 5 |
2 files changed, 28 insertions, 5 deletions
diff --git a/compiler/typecheck/TcExpr.hs b/compiler/typecheck/TcExpr.hs index a087917240..9eaead5935 100644 --- a/compiler/typecheck/TcExpr.hs +++ b/compiler/typecheck/TcExpr.hs @@ -1331,8 +1331,9 @@ tcArgs fun orig_fun_ty fun_orig orig_args herald ; case tcSplitForAllTy_maybe upsilon_ty of Just (tvb, inner_ty) | binderArgFlag tvb == Specified -> - -- It really can't be Inferred, because we've just instantiated those - -- But, oddly, it might just be Required. See #15859. + -- It really can't be Inferred, because we've justn + -- instantiated those. But, oddly, it might just be Required. + -- See Note [Required quantifiers in the type of a term] do { let tv = binderVar tvb kind = tyVarKind tv ; ty_arg <- tcHsTypeApp hs_ty_arg kind @@ -1381,8 +1382,27 @@ tcArgs fun orig_fun_ty fun_orig orig_args herald text "Cannot apply expression of type" <+> quotes (ppr ty) $$ text "to a visible type argument" <+> quotes (ppr arg) } -{- Note [Visible type application zonk] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +{- Note [Required quantifiers in the type of a term] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Consider (Trac #15859) + + data A k :: k -> Type -- A :: forall k -> k -> Type + type KindOf (a :: k) = k -- KindOf :: forall k. k -> Type + a = (undefind :: KindOf A) @Int + +With ImpredicativeTypes (thin ice, I know), we instantiate +KindOf at type (forall k -> k -> Type), so + KindOf A = forall k -> k -> Type +whose first argument is Required + +We want to reject this type application to Int, but in earlier +GHCs we had an ASSERT that Required could not occur here. + +The ice is thin; c.f. Note [No Required TyCoBinder in terms] +in TyCoRep. + +Note [Visible type application zonk] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Substitutions should be kind-preserving, so we need kind(tv) = kind(ty_arg). * tcHsTypeApp only guarantees that diff --git a/compiler/types/TyCoRep.hs b/compiler/types/TyCoRep.hs index 1c0d5f9dd2..d6c0f33e04 100644 --- a/compiler/types/TyCoRep.hs +++ b/compiler/types/TyCoRep.hs @@ -711,7 +711,7 @@ See also Note [Required, Specified, and Inferred for types] in TcTyClsDecls Visible Type Applications paper (ESOP'16). Note [No Required TyCoBinder in terms] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ We don't allow Required foralls for term variables, including pattern synonyms and data constructors. Why? Because then an application would need a /compulsory/ type argument (possibly without an "@"?), @@ -719,6 +719,9 @@ thus (f Int); and we don't have concrete syntax for that. We could change this decision, but Required, Named TyCoBinders are rare anyway. (Most are Anons.) + +However the type of a term can (just about) have a required quantifier; +see Note [Required quantifiers in the type of a term] in TcExpr. -} |
