summaryrefslogtreecommitdiff
path: root/testsuite/tests/typecheck/should_run/T3731_simple.hs
blob: c1f6758ebd9393b62ddb7cbebac45d7856ccbfc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{-# LANGUAGE
  FlexibleInstances,
  UndecidableInstances
#-}

module Bug where

class Default a
class Sat a

instance Default a => Sat a

class Sat a => Data a where
  dataTypeOf :: a -> a

defaultDefaultValue :: Data a => a
defaultDefaultValue = res
    where
      res = dataTypeOf res

-- GHC does not infer the principal type for res,
-- inferring (Default a, Data a) => a instead of Data a => a.
-- See Note [Inferring principal types] in Ghc.Tc.Solver
--
-- This used to be fine, as "Default a" was a Derived constraint
-- that could be dropped. Without Deriveds, we instead get a
-- Wanted constraint, which can't be dropped.
-- This means that this program no longer compiles.
-- (Note that a type signature on "res" allows the program to
-- compile again.)