summaryrefslogtreecommitdiff
path: root/libraries
diff options
context:
space:
mode:
authorDavid Kraeutmann <kane@kane.cx>2015-07-07 16:59:52 +0200
committerBen Gamari <ben@smart-cactus.org>2015-07-07 16:59:52 +0200
commit9a3e1657db4c0292fc06d6183a802af631c3666a (patch)
treef18d0fb8619e580a69ce99c4c107bd9b43450180 /libraries
parent31580e2c81543a58c0d352154c6109d843978cdf (diff)
downloadhaskell-9a3e1657db4c0292fc06d6183a802af631c3666a.tar.gz
Deferred type errors now throw TypeError (#10284)
Depends on D864. Previous behaviour was ErrorCall, which might mask issues in tests using -fdefer-type-errors Signed-off-by: David Kraeutmann <kane@kane.cx> Test Plan: Test whether the error thrown is indeed TypeError and not ErrorCall. Reviewers: hvr, nomeata, austin Reviewed By: nomeata, austin Subscribers: nomeata, simonpj, thomie Differential Revision: https://phabricator.haskell.org/D866 GHC Trac Issues: #10284
Diffstat (limited to 'libraries')
-rw-r--r--libraries/base/Control/Exception.hs1
-rw-r--r--libraries/base/Control/Exception/Base.hs18
2 files changed, 17 insertions, 2 deletions
diff --git a/libraries/base/Control/Exception.hs b/libraries/base/Control/Exception.hs
index 18c0e42914..61ebf2961c 100644
--- a/libraries/base/Control/Exception.hs
+++ b/libraries/base/Control/Exception.hs
@@ -56,6 +56,7 @@ module Control.Exception (
RecSelError(..),
RecUpdError(..),
ErrorCall(..),
+ TypeError(..),
-- * Throwing exceptions
throw,
diff --git a/libraries/base/Control/Exception/Base.hs b/libraries/base/Control/Exception/Base.hs
index 4608c2dd20..4318773d35 100644
--- a/libraries/base/Control/Exception/Base.hs
+++ b/libraries/base/Control/Exception/Base.hs
@@ -39,6 +39,7 @@ module Control.Exception.Base (
RecSelError(..),
RecUpdError(..),
ErrorCall(..),
+ TypeError(..), -- #10284, custom error type for deferred type errors
-- * Throwing exceptions
throwIO,
@@ -92,7 +93,7 @@ module Control.Exception.Base (
-- * Calls for GHC runtime
recSelError, recConError, irrefutPatError, runtimeError,
nonExhaustiveGuardsError, patError, noMethodBindingError,
- absentError,
+ absentError, typeError,
nonTermination, nestedAtomically,
) where
@@ -357,6 +358,18 @@ instance Exception NoMethodError
-----
+-- |An expression that didn't typecheck during compile time was called.
+-- This is only possible with -fdefer-type-errors. The @String@ gives
+-- details about the failed type check.
+data TypeError = TypeError String
+
+instance Show TypeError where
+ showsPrec _ (TypeError err) = showString err
+
+instance Exception TypeError
+
+-----
+
-- |Thrown when the runtime system detects that the computation is
-- guaranteed not to terminate. Note that there is no guarantee that
-- the runtime system will notice whether any given computation is
@@ -383,7 +396,7 @@ instance Exception NestedAtomically
recSelError, recConError, irrefutPatError, runtimeError,
nonExhaustiveGuardsError, patError, noMethodBindingError,
- absentError
+ absentError, typeError
:: Addr# -> a -- All take a UTF8-encoded C string
recSelError s = throw (RecSelError ("No match in record selector "
@@ -396,6 +409,7 @@ irrefutPatError s = throw (PatternMatchFail (untangle s "Irrefutable pa
recConError s = throw (RecConError (untangle s "Missing field in record construction"))
noMethodBindingError s = throw (NoMethodError (untangle s "No instance nor default method for class operation"))
patError s = throw (PatternMatchFail (untangle s "Non-exhaustive patterns in"))
+typeError s = throw (TypeError (unpackCStringUtf8# s))
-- GHC's RTS calls this
nonTermination :: SomeException