diff options
author | Tom Smeding <tom.smeding@gmail.com> | 2020-07-27 10:32:49 +0200 |
---|---|---|
committer | Tom Smeding <tom.smeding@gmail.com> | 2020-07-27 10:32:49 +0200 |
commit | 4c9e6c7dc4468c05553b04ba0c1aca6964dc0f82 (patch) | |
tree | 48a6ec7c60d90a0cd45a600b1963ad3ea6466e8a /typecheck/CC/Typecheck/Types.hs | |
parent | 1ac7ba99fc809958ab59ed9b81df6fda7f2dbf05 (diff) |
Diffstat (limited to 'typecheck/CC/Typecheck/Types.hs')
-rw-r--r-- | typecheck/CC/Typecheck/Types.hs | 15 |
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 |