summaryrefslogtreecommitdiff
path: root/testsuite
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2017-11-08 08:45:53 +0000
committerSimon Peyton Jones <simonpj@microsoft.com>2017-11-08 11:12:35 +0000
commit30058b0e45e920319916be999de9c4d77da136e7 (patch)
tree948627521cf67ac580e43a3e248e189e00d03bd5 /testsuite
parent21970de8bf810970a9f4d634d53ea02b2cb248db (diff)
downloadhaskell-30058b0e45e920319916be999de9c4d77da136e7.tar.gz
Fix another dark corner in the shortcut solver
The shortcut solver for type classes (Trac #12791) was eagerly solving a constaint from an OVERLAPPABLE instance. It happened to be the only one in scope, so it was unique, but since it's specfically flagged as overlappable it's really a bad idea to solve using it, rather than using the Given dictionary. This led to Trac #14434, a nasty and hard to identify bug.
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/tests/typecheck/should_compile/T14434.hs17
-rw-r--r--testsuite/tests/typecheck/should_compile/T14434.stdout2
-rw-r--r--testsuite/tests/typecheck/should_compile/all.T1
3 files changed, 20 insertions, 0 deletions
diff --git a/testsuite/tests/typecheck/should_compile/T14434.hs b/testsuite/tests/typecheck/should_compile/T14434.hs
new file mode 100644
index 0000000000..a0d0442fed
--- /dev/null
+++ b/testsuite/tests/typecheck/should_compile/T14434.hs
@@ -0,0 +1,17 @@
+{-# LANGUAGE MonoLocalBinds, FlexibleInstances, OverloadedStrings #-}
+{-# OPTIONS -fsolve-constant-dicts #-}
+
+module T14434 where
+
+class ToString a where
+ toString :: a -> String
+
+-- | This instance is used in original code as hack
+-- to simplify code generation
+instance {-# OVERLAPPABLE #-} ToString a where
+ toString _ = "Catchall attribute value"
+
+toStringX :: (ToString a) => a -> String
+toStringX = toString
+ -- Here we do /not/ want to solve the ToString
+ -- constraint with the local instance
diff --git a/testsuite/tests/typecheck/should_compile/T14434.stdout b/testsuite/tests/typecheck/should_compile/T14434.stdout
new file mode 100644
index 0000000000..f1436e3959
--- /dev/null
+++ b/testsuite/tests/typecheck/should_compile/T14434.stdout
@@ -0,0 +1,2 @@
+toStringX :: forall a. ToString a => a -> String
+toStringX = toString
diff --git a/testsuite/tests/typecheck/should_compile/all.T b/testsuite/tests/typecheck/should_compile/all.T
index e799a45669..03e70915d4 100644
--- a/testsuite/tests/typecheck/should_compile/all.T
+++ b/testsuite/tests/typecheck/should_compile/all.T
@@ -581,3 +581,4 @@ test('T14333', normal, compile, [''])
test('T14363', normal, compile, [''])
test('T14363a', normal, compile, [''])
test('T7169', normal, compile, [''])
+test('T14434', [], run_command, ['$MAKE -s --no-print-directory T14434'])