Fix Trac #4841: behave right with TypeSynonymInstances and NoFlexibleInstances
authorsimonpj@microsoft.com <unknown>
Tue, 14 Dec 2010 17:47:55 +0000 (17:47 +0000)
committersimonpj@microsoft.com <unknown>
Tue, 14 Dec 2010 17:47:55 +0000 (17:47 +0000)
When we have TypeSynonymInstances without FlexibleInstances we should still
insist on a H98-style instance head, after looking through the synonym.

This patch also make FlexibleInstances imply TypeSynonymInstances.  Anything
else is a bit awkward, and not very useful.

compiler/main/DynFlags.hs
compiler/typecheck/TcType.lhs
docs/users_guide/flags.xml

index e3de006..8f6f45d 100644 (file)
@@ -1658,6 +1658,7 @@ impliedFlags
     , (Opt_LiberalTypeSynonyms,       turnOn, Opt_ExplicitForAll)
     , (Opt_ExistentialQuantification, turnOn, Opt_ExplicitForAll)
     , (Opt_PolymorphicComponents,     turnOn, Opt_ExplicitForAll)
+    , (Opt_FlexibleInstances,         turnOn, Opt_TypeSynonymInstances)
 
     , (Opt_RebindableSyntax, turnOff, Opt_ImplicitPrelude)      -- NB: turn off!
 
index 89aba65..50ac35a 100644 (file)
@@ -956,6 +956,9 @@ tcInstHeadTyAppAllTyVars :: Type -> Bool
 -- Used in Haskell-98 mode, for the argument types of an instance head
 -- These must be a constructor applied to type variable arguments
 tcInstHeadTyAppAllTyVars ty
+  | Just ty' <- tcView ty       -- Look through synonyms
+  = tcInstHeadTyAppAllTyVars ty'
+  | otherwise
   = case ty of
        TyConApp _ tys  -> ok tys
        FunTy arg res   -> ok [arg, res]
index c8e5dfc..2bcb5e6 100644 (file)
            </row>
            <row>
              <entry><option>-XFlexibleInstances</option></entry>
-             <entry>Enable <link linkend="instance-rules">flexible instances</link>.</entry>
-             <entry>dynamic</entry>
+              <entry>Enable <link linkend="instance-rules">flexible instances</link>.
+              Implies <option>-XTypeSynonymInstances</option> </entry>
+              <entry>dynamic</entry>
              <entry><option>-XNoFlexibleInstances</option></entry>
            </row>
            <row>