From bdaf685ced63faab7353717c01999e582efb4e37 Mon Sep 17 00:00:00 2001 From: "simonpj@microsoft.com" Date: Tue, 6 Nov 2007 15:31:51 +0000 Subject: [PATCH] Fix Trac #1813: generalise over *all* type variables at top level, even phantom ones See Note [Silly type synonym] in TcType for further details. This bug (or at least infelicity) has been in GHC for quite a long time. --- compiler/typecheck/TcBinds.lhs | 6 +++--- compiler/typecheck/TcType.lhs | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/compiler/typecheck/TcBinds.lhs b/compiler/typecheck/TcBinds.lhs index f27637d..d0044d4 100644 --- a/compiler/typecheck/TcBinds.lhs +++ b/compiler/typecheck/TcBinds.lhs @@ -741,9 +741,9 @@ generalise dflags top_lvl bind_list sig_fn mono_infos lie_req where bndrs = bndrNames mono_infos sigs = [sig | (_, Just sig, _) <- mono_infos] - tau_tvs = foldr (unionVarSet . exactTyVarsOfType . getMonoType) emptyVarSet mono_infos - -- NB: exactTyVarsOfType; see Note [Silly type synonym] - -- near defn of TcType.exactTyVarsOfType + get_tvs | isTopLevel top_lvl = tyVarsOfType -- See Note [Silly type synonym] in TcType + | otherwise = exactTyVarsOfType + tau_tvs = foldr (unionVarSet . get_tvs . getMonoType) emptyVarSet mono_infos is_mono_sig sig = null (sig_theta sig) doc = ptext SLIT("type signature(s) for") <+> pprBinders bndrs diff --git a/compiler/typecheck/TcType.lhs b/compiler/typecheck/TcType.lhs index 636ee0e..625f855 100644 --- a/compiler/typecheck/TcType.lhs +++ b/compiler/typecheck/TcType.lhs @@ -1062,6 +1062,15 @@ exactTyVarsOfType is used by the type checker to figure out exactly which type variables are mentioned in a type. It's also used in the smart-app checking code --- see TcExpr.tcIdApp +On the other hand, consider a *top-level* definition + f = (\x -> x) :: T a -> T a +If we don't abstract over 'a' it'll get fixed to GHC.Prim.Any, and then +if we have an application like (f "x") we get a confusing error message +involving Any. So the conclusion is this: when generalising + - at top level use tyVarsOfType + - in nested bindings use exactTyVarsOfType +See Trac #1813 for example. + \begin{code} exactTyVarsOfType :: TcType -> TyVarSet -- Find the free type variables (of any kind) -- 1.7.10.4