Two new warnings: arity differing from demand type, and strict IDs at top level
[ghc-hetmet.git] / compiler / typecheck / TcSimplify.lhs
index 342114b..29938ee 100644 (file)
@@ -849,10 +849,11 @@ bindIrredsR loc qtvs co_vars reft givens irreds
                -- The givens can include methods
                -- See Note [Pruning the givens in an implication constraint]
 
-          -- If there are no 'givens', then it's safe to 
+          -- If there are no 'givens' *and* the refinement is empty
+          -- (the refinement is like more givens), then it's safe to 
           -- partition the 'wanteds' by their qtvs, thereby trimming irreds
           -- See Note [Freeness and implications]
-       ; irreds' <- if null givens'
+       ; irreds' <- if null givens' && isEmptyRefinement reft
                     then do
                        { let qtv_set = mkVarSet qtvs
                              (frees, real_irreds) = partition (isFreeWrtTyVars qtv_set) irreds
@@ -2257,8 +2258,13 @@ disambiguate extended_defaulting insts
                                do { integer_ty <- tcMetaTy integerTyConName
                                   ; checkWiredInTyCon doubleTyCon
                                   ; return [integer_ty, doubleTy] }
+        ; string_ty <- tcMetaTy stringTyConName
+       ; ovlStr <- doptM Opt_OverloadedStrings
+       -- XXX This should not be added unconditionally, but the default declaration stuff
+       -- is too wired to Num for me to understand.  /LA
+        ; let default_str_tys = default_tys ++ if ovlStr then [string_ty] else []
        ; traceTc (text "disambigutate" <+> vcat [ppr unaries, ppr bad_tvs, ppr defaultable_groups])
-       ; mapM_ (disambigGroup default_tys) defaultable_groups  }
+       ; mapM_ (disambigGroup default_str_tys) defaultable_groups  }
   where
    unaries :: [(Inst,Class, TcTyVar)]  -- (C tv) constraints
    bad_tvs :: TcTyVarSet         -- Tyvars mentioned by *other* constraints
@@ -2278,13 +2284,13 @@ disambiguate extended_defaulting insts
 
    defaultable_classes clss 
        | extended_defaulting = any isInteractiveClass clss
-       | otherwise = all isStandardClass clss && any isNumericClass clss
+       | otherwise = all isStandardClass clss && (any isNumericClass clss || any ((== isStringClassKey) . classKey) clss)
 
        -- In interactive mode, or with -fextended-default-rules,
        -- we default Show a to Show () to avoid graututious errors on "show []"
    isInteractiveClass cls 
        = isNumericClass cls
-       || (classKey cls `elem` [showClassKey, eqClassKey, ordClassKey])
+       || (classKey cls `elem` [showClassKey, eqClassKey, ordClassKey, isStringClassKey])
 
 
 disambigGroup :: [Type]                        -- The default types
@@ -2359,14 +2365,18 @@ tcSimplifyDeriv orig tyvars theta
        ; wanteds <- newDictBndrsO orig (substTheta tenv theta)
        ; (irreds, _) <- topCheckLoop doc wanteds
 
-       ; let (dicts, non_dicts) = partition isDict irreds
-                                       -- Exclude implication consraints
-       ; addNoInstanceErrs non_dicts   -- I'm not sure if these can really happen
+       -- Insist that the context of a derived instance declaration
+       -- consists of constraints of form (C a b), where a,b are
+       -- type variables
+       -- NB: the caller will further check the tv_dicts for
+       --     legal instance-declaration form
+       ; let (tv_dicts, non_tv_dicts) = partition isTyVarDict irreds
+       ; addNoInstanceErrs non_tv_dicts
 
        ; let rev_env = zipTopTvSubst tvs (mkTyVarTys tyvars)
-             simpl_theta = substTheta rev_env (map dictPred dicts)
-               -- This reverse-mapping is a Royal Pain, 
-               -- but the result should mention TyVars not TcTyVars
+             simpl_theta = substTheta rev_env (map dictPred tv_dicts)
+               -- This reverse-mapping is a pain, but the result
+               -- should mention the original TyVars not TcTyVars
 
        ; return simpl_theta }
   where