summaryrefslogtreecommitdiff
path: root/testsuite/tests/typecheck/should_run/T3731_simple.hs
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/tests/typecheck/should_run/T3731_simple.hs')
-rw-r--r--testsuite/tests/typecheck/should_run/T3731_simple.hs30
1 files changed, 30 insertions, 0 deletions
diff --git a/testsuite/tests/typecheck/should_run/T3731_simple.hs b/testsuite/tests/typecheck/should_run/T3731_simple.hs
new file mode 100644
index 0000000000..c1f6758ebd
--- /dev/null
+++ b/testsuite/tests/typecheck/should_run/T3731_simple.hs
@@ -0,0 +1,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.)