aboutsummaryrefslogtreecommitdiff
path: root/typecheck/CC/Typecheck/Types.hs
diff options
context:
space:
mode:
Diffstat (limited to 'typecheck/CC/Typecheck/Types.hs')
-rw-r--r--typecheck/CC/Typecheck/Types.hs15
1 files changed, 12 insertions, 3 deletions
diff --git a/typecheck/CC/Typecheck/Types.hs b/typecheck/CC/Typecheck/Types.hs
index 3009ca1..dc0740d 100644
--- a/typecheck/CC/Typecheck/Types.hs
+++ b/typecheck/CC/Typecheck/Types.hs
@@ -14,17 +14,22 @@ import CC.Pretty
import CC.Types
-data TCError = TypeError SourceRange T.Type T.Type
+data TCError = UnifyError SourceRange T.Type T.Type T.Type T.Type (Maybe UnifyReason)
| RefError SourceRange Name
| TypeArityError SourceRange Name Int Int
| DupTypeError Name
deriving (Show)
+data UnifyReason = URNotInUnion | URAmbiguousWeakening
+ deriving (Show)
+
instance Pretty TCError where
- pretty (TypeError sr real expect) =
+ pretty (UnifyError sr real expect unifyt1 unifyt2 mreason) =
"Type error: Expression at " ++ pretty sr ++
" has type " ++ pretty real ++
- ", but should have type " ++ pretty expect
+ ", but should have type " ++ pretty expect ++
+ " (when unifying " ++ pretty unifyt1 ++ " and " ++ pretty unifyt2 ++ ")" ++
+ maybe "" (\r -> " (reason: " ++ pretty r ++ ")") mreason
pretty (RefError sr name) =
"Reference error: Variable '" ++ name ++ "' out of scope at " ++ pretty sr
pretty (TypeArityError sr name wanted got) =
@@ -33,6 +38,10 @@ instance Pretty TCError where
pretty (DupTypeError name) =
"Duplicate types: Type '" ++ name ++ "' defined multiple times"
+instance Pretty UnifyReason where
+ pretty URNotInUnion = "type not found in union"
+ pretty URAmbiguousWeakening = "type unifies with multiple items in the union"
+
type TM a = ExceptT TCError (State Int) a
genId :: TM Int