@@ -2,7 +2,23 @@
2{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Reporting.Error.Type
3module Reporting.Error.Type
4 ( Error(..)
4 ( Error(..)
5 , Origin(..)
6 , Origin(..)
6 , toReport
22 , toReport
@@ -11,17 +27,14 @@ module Reporting.Error.Type
11import Prelude hiding (round)
27import Prelude hiding (round)
12import Data.Monoid ((<>))
28import Data.Monoid ((<>))
14−import qualified AST.Canonical as Can
15import qualified AST.Module.Name as ModuleName
30import qualified AST.Module.Name as ModuleName
16−import qualified AST.Utils.Type as Type
17import qualified Data.Index as Index
31import qualified Data.Index as Index
32+import qualified Data.Map as Map
18import qualified Elm.Name as N
33import qualified Elm.Name as N
19import qualified Reporting.Helpers as H
34import qualified Reporting.Helpers as H
20import qualified Reporting.Region as R
35import qualified Reporting.Region as R
21import qualified Reporting.Render.Code as Code
36import qualified Reporting.Render.Code as Code
22−import qualified Reporting.Render.Type as Type
23import qualified Reporting.Report as Report
37import qualified Reporting.Report as Report
24−import qualified Type.Constraint as C
@@ -29,22 +42,159 @@ import qualified Type.Constraint as C
32− = Mismatch Origin (C.Expected Can.Type)
45+ = Mismatch Origin (Expected Type)
33− | BadPattern R.Region C.PCategory Can.Type (C.PExpected Can.Type)
46+ | BadPattern R.Region PCategory Type (PExpected Type)
34− | InfiniteType Can.Type
47+ | InfiniteType Type
51+-- EXPRESSION EXPECTATIONS
37data Origin
54data Origin
38− = BadExpr R.Region C.Category Can.Type
55+ = BadExpr R.Region Category Type
39− | BadLocal R.Region N.Name Can.Type
56+ | BadLocal R.Region N.Name Type
40− | BadForeign R.Region N.Name Can.Type
57+ | BadForeign R.Region N.Name Type
62+ | FromContext R.Region Context tipe
63+ | FromAnnotation N.Name Int SubContext tipe
67+ = ListEntry Index.ZeroBased
72+ | IfBranch Index.ZeroBased
73+ | CaseBranch Index.ZeroBased
74+ | CallArg MaybeName Index.ZeroBased
75+ | TooManyArgs MaybeName Int
76+ | RecordAccess N.Name
82+ = TypedIfBranch Index.ZeroBased
83+ | TypedCaseBranch Index.ZeroBased
102+ | CallResult MaybeName
114+-- PATTERN EXPECTATIONS
118+ = PNoExpectation tipe
119+ | PFromContext R.Region PContext tipe
123+ = PTypedArg N.Name Index.ZeroBased
124+ | PCaseMatch Index.ZeroBased
125+ | PCtorArg N.Name Index.ZeroBased
126+ | PListEntry Index.ZeroBased
145+typeReplace :: Expected a -> b -> Expected b
146+typeReplace expectation tipe =
151+ FromContext region context _ ->
152+ FromContext region context tipe
154+ FromAnnotation name arity context _ ->
155+ FromAnnotation name arity context tipe
158+ptypeReplace :: PExpected a -> b -> PExpected b
159+ptypeReplace expectation tipe =
164+ PFromContext region context _ ->
165+ PFromContext region context tipe
173+ = Lambda Type [Type]
180+ | Type ModuleName.Canonical N.Name [Type]
181+ | Record (Map.Map N.Name Type) Extension
183+ | Tuple Type Type (Maybe Type)
184+ | Alias ModuleName.Canonical N.Name [(N.Name, Type)] Type
44-- TO REPORT
194-- TO REPORT
47−toReport :: Code.Source -> Type.Localizer -> Error -> Report.Report
197+toReport :: Code.Source -> Localizer -> Error -> Report.Report
48toReport source localizer err =
198toReport source localizer err =
49 case err of
199 case err of
50 Mismatch origin expected ->
200 Mismatch origin expected ->
@@ -71,27 +221,7 @@ toReport source localizer err =
72data Thing
222data Thing
73 = Var N.Name
223 = Var N.Name
74− | Category C.Category
224+ | Category Category
77−typeComparison :: Type.Localizer -> Can.Type -> Can.Type -> ( String, String, [H.Doc] ) -> H.Doc
78−typeComparison localizer actual expected ( iAmSeeing, insteadOf, soHereAreSomeThoughts ) =
80− (actualDoc, expectedDoc) =
81− Type.diffToDocs localizer actual expected
85− , H.indent 4 actualDoc
87− , H.indent 4 expectedDoc
89− ++ soHereAreSomeThoughts
92−indentType :: Type.Localizer -> Can.Type -> H.Doc
93−indentType localizer tipe =
94− H.indent 4 (H.dullyellow (Type.toDoc localizer tipe))
97toDescription :: Thing -> String -> String
227toDescription :: Thing -> String -> String
@@ -102,38 +232,38 @@ toDescription thing thatThingIs =
103 Category category ->
233 Category category ->
104 case category of
234 case category of
105− C.List -> thatThingIs <> " a list of type:"
235+ List -> thatThingIs <> " a list of type:"
106− C.Number -> thatThingIs <> " a number of type:"
236+ Number -> thatThingIs <> " a number of type:"
107− C.Float -> thatThingIs <> " a float of type:"
237+ Float -> thatThingIs <> " a float of type:"
108− C.String -> thatThingIs <> " a string of type:"
238+ String -> thatThingIs <> " a string of type:"
109− C.Char -> thatThingIs <> " a character of type:"
239+ Char -> thatThingIs <> " a character of type:"
110− C.If -> "This `if` expression produces a value of type:"
240+ If -> "This `if` expression produces a value of type:"
111− C.Case -> "This `case` expression produces a value of type:"
241+ Case -> "This `case` expression produces a value of type:"
112− C.Lambda -> thatThingIs <> " an anonymous function of type:"
242+ LambdaExpr -> thatThingIs <> " an anonymous function of type:"
113− C.Accessor field -> "This ." <> N.toString field <> " field access function has type of type:"
243+ Accessor field -> "This ." <> N.toString field <> " field access function has type:"
114− C.Access field -> "The value at ." <> N.toString field <> " has type of type:"
244+ Access field -> "The value at ." <> N.toString field <> " has type:"
115− C.Record -> thatThingIs <> " a record of type:"
245+ RecordExpr -> thatThingIs <> " a record of type:"
116− C.Tuple -> thatThingIs <> " a tuple of type:"
246+ TupleExpr -> thatThingIs <> " a tuple of type:"
117− C.Unit -> thatThingIs <> " a unit value:"
247+ UnitExpr -> thatThingIs <> " a unit value:"
118− C.Shader -> thatThingIs <> " a GLSL shader of type:"
248+ Shader -> thatThingIs <> " a GLSL shader of type:"
119− C.Effects -> thatThingIs <> " a thing for CORE LIBRARIES ONLY."
249+ Effects -> thatThingIs <> " a thing for CORE LIBRARIES ONLY."
120− C.CallResult maybeName ->
250+ CallResult maybeName ->
121 case maybeName of
251 case maybeName of
122− C.NoName -> thatThingIs <> ":"
252+ NoName -> thatThingIs <> ":"
123− C.FuncName name -> "This `" <> N.toString name <> "` call produces:"
253+ FuncName name -> "This `" <> N.toString name <> "` call produces:"
124− C.CtorName name -> "This `" <> N.toString name <> "` call produces:"
254+ CtorName name -> "This `" <> N.toString name <> "` call produces:"
125− C.OpName _ -> thatThingIs <> ":"
255+ OpName _ -> thatThingIs <> ":"
129-- TO MISMATCH REPORT
259-- TO MISMATCH REPORT
132−toMismatchReport :: Code.Source -> Type.Localizer -> R.Region -> Thing -> Can.Type -> C.Expected Can.Type -> Report.Report
262+toMismatchReport :: Code.Source -> Localizer -> R.Region -> Thing -> Type -> Expected Type -> Report.Report
133toMismatchReport source localizer exprRegion thing tipe expected =
263toMismatchReport source localizer exprRegion thing tipe expected =
134 Report.Report "TYPE MISMATCH" exprRegion [] $
264 Report.Report "TYPE MISMATCH" exprRegion [] $
135 case expected of
265 case expected of
136− C.NoExpectation expectedType ->
266+ NoExpectation expectedType ->
137 Report.toCodeSnippet source exprRegion Nothing
267 Report.toCodeSnippet source exprRegion Nothing
139 "This expression is being used in an unexpected way:"
269 "This expression is being used in an unexpected way:"
@@ -150,31 +280,31 @@ toMismatchReport source localizer exprRegion thing tipe expected =
153− C.FromAnnotation name arity subContext expectedType ->
283+ FromAnnotation name arity subContext expectedType ->
154 Report.toCodeSnippet source exprRegion Nothing
284 Report.toCodeSnippet source exprRegion Nothing
156 H.reflow $
286 H.reflow $
157 case subContext of
287 case subContext of
158− C.TypedIfBranch index ->
288+ TypedIfBranch index ->
159 "Something is off with the " <> H.ordinalize (Index.toHuman index) <> " branch of this `if` experssion:"
289 "Something is off with the " <> H.ordinalize (Index.toHuman index) <> " branch of this `if` experssion:"
161− C.TypedCaseBranch index ->
291+ TypedCaseBranch index ->
162 "Something is off with the " <> H.ordinalize (Index.toHuman index) <> " branch of this `case` expression:"
292 "Something is off with the " <> H.ordinalize (Index.toHuman index) <> " branch of this `case` expression:"
164− C.TypedBody ->
294+ TypedBody ->
165 "Something is off with the body of the `" <> N.toString name <> "` definition:"
295 "Something is off with the body of the `" <> N.toString name <> "` definition:"
167 typeComparison localizer tipe expectedType
297 typeComparison localizer tipe expectedType
169 toDescription thing $
299 toDescription thing $
170 case subContext of
300 case subContext of
171− C.TypedIfBranch index ->
301+ TypedIfBranch index ->
172 "The " <> H.ordinalize (Index.toHuman index) <> " branch is"
302 "The " <> H.ordinalize (Index.toHuman index) <> " branch is"
174− C.TypedCaseBranch index ->
304+ TypedCaseBranch index ->
175 "The " <> H.ordinalize (Index.toHuman index) <> " branch is"
305 "The " <> H.ordinalize (Index.toHuman index) <> " branch is"
177− C.TypedBody ->
307+ TypedBody ->
178 "The body is"
308 "The body is"
180 "But the type annotation on `" <> N.toString name <> "` says it should be:"
310 "But the type annotation on `" <> N.toString name <> "` says it should be:"
@@ -185,9 +315,9 @@ toMismatchReport source localizer exprRegion thing tipe expected =
188− C.FromContext region context expectedType ->
318+ FromContext region context expectedType ->
189 case context of
319 case context of
190− C.ListEntry index ->
320+ ListEntry index ->
191 if Index.toHuman index == 2 then
321 if Index.toHuman index == 2 then
192 error "TODO 1st vs 2nd list entry"
322 error "TODO 1st vs 2nd list entry"
@@ -213,7 +343,7 @@ toMismatchReport source localizer exprRegion thing tipe expected =
216− C.Negate ->
346+ Negate ->
217 Report.toCodeSnippet source region (Just exprRegion)
347 Report.toCodeSnippet source region (Just exprRegion)
219 "I do not know how to negate this type of value:"
349 "I do not know how to negate this type of value:"
@@ -229,15 +359,19 @@ toMismatchReport source localizer exprRegion thing tipe expected =
232− C.OpLeft op ->
362+ OpLeft op ->
233 Report.toCodeSnippet source region (Just exprRegion) $
363 Report.toCodeSnippet source region (Just exprRegion) $
234 opLeftToDocs localizer thing op tipe expectedType
364 opLeftToDocs localizer thing op tipe expectedType
236− C.OpRight op ->
366+ OpRight op ->
237− Report.toCodeSnippet source region (Just exprRegion) $
238− opRightToDocs localizer thing op tipe expectedType
367+ case opRightToDocs localizer thing op tipe expectedType of
369+ Report.toCodeSnippet source region Nothing details
371+ EmphRight details ->
372+ Report.toCodeSnippet source region (Just exprRegion) details
240− C.IfCondition ->
374+ IfCondition ->
241 Report.toCodeSnippet source region (Just exprRegion)
375 Report.toCodeSnippet source region (Just exprRegion)
243 "This `if` condition does not evaluate to a boolean value, True or False."
377 "This `if` condition does not evaluate to a boolean value, True or False."
@@ -252,7 +386,7 @@ toMismatchReport source localizer exprRegion thing tipe expected =
255− C.IfBranch index ->
389+ IfBranch index ->
256 if Index.toHuman index == 2 then
390 if Index.toHuman index == 2 then
257 error "TODO 1st vs 2nd if branches"
391 error "TODO 1st vs 2nd if branches"
258 -- error "TODO if with no chaining"
392 -- error "TODO if with no chaining"
@@ -279,7 +413,7 @@ toMismatchReport source localizer exprRegion thing tipe expected =
282− C.CaseBranch index ->
416+ CaseBranch index ->
283 if Index.toHuman index == 2 then
417 if Index.toHuman index == 2 then
284 error "TODO 1st vs 2nd case branches"
418 error "TODO 1st vs 2nd case branches"
@@ -305,20 +439,20 @@ toMismatchReport source localizer exprRegion thing tipe expected =
308− C.CallArg maybeFuncName index ->
442+ CallArg maybeFuncName index ->
310 thisFunction =
444 thisFunction =
311 case maybeFuncName of
445 case maybeFuncName of
312− C.NoName ->
446+ NoName ->
313 "this function"
447 "this function"
315− C.FuncName name ->
449+ FuncName name ->
316 "`" <> N.toString name <> "`"
450 "`" <> N.toString name <> "`"
318− C.CtorName name ->
452+ CtorName name ->
319 "`" <> N.toString name <> "`"
453 "`" <> N.toString name <> "`"
321− C.OpName op ->
455+ OpName op ->
322 "(" <> N.toString op <> ")"
456 "(" <> N.toString op <> ")"
@@ -345,38 +479,38 @@ toMismatchReport source localizer exprRegion thing tipe expected =
348− C.TooManyArgs maybeName numGivenArgs ->
482+ TooManyArgs maybeName numGivenArgs ->
349− case length (Type.delambda tipe) - 1 of
483+ case countArgs tipe of
351 Report.toCodeSnippet source region (Just exprRegion)
485 Report.toCodeSnippet source region (Just exprRegion)
353 H.reflow $
487 H.reflow $
354 case maybeName of
488 case maybeName of
355− C.NoName ->
489+ NoName ->
356 "You are giving " <> H.args numGivenArgs <> " to something that is not a function!"
490 "You are giving " <> H.args numGivenArgs <> " to something that is not a function!"
358− C.FuncName name ->
492+ FuncName name ->
359 "`" <> N.toString name <> "` is not a function, but you are giving it " <> H.args numGivenArgs <> "!"
493 "`" <> N.toString name <> "` is not a function, but you are giving it " <> H.args numGivenArgs <> "!"
361− C.CtorName name ->
495+ CtorName name ->
362 "`" <> N.toString name <> "` is not a function, but you are giving it " <> H.args numGivenArgs <> "!"
496 "`" <> N.toString name <> "` is not a function, but you are giving it " <> H.args numGivenArgs <> "!"
364− C.OpName op ->
498+ OpName op ->
365 "(" <> N.toString op <> ") is not a function, but you are giving it " <> H.args numGivenArgs <> "!"
499 "(" <> N.toString op <> ") is not a function, but you are giving it " <> H.args numGivenArgs <> "!"
367 typeComparison localizer tipe expectedType
501 typeComparison localizer tipe expectedType
369 case maybeName of
503 case maybeName of
370− C.NoName ->
504+ NoName ->
371 "It is a value of type:"
505 "It is a value of type:"
373− C.FuncName name ->
507+ FuncName name ->
374 "`" <> N.toString name <> "` is a value of type:"
508 "`" <> N.toString name <> "` is a value of type:"
376− C.CtorName name ->
510+ CtorName name ->
377 "`" <> N.toString name <> "` is a constructor of type:"
511 "`" <> N.toString name <> "` is a constructor of type:"
379− C.OpName op ->
513+ OpName op ->
380 "(" <> N.toString op <> ") is a value of type:"
514 "(" <> N.toString op <> ") is a value of type:"
382 "But you are giving it " <> H.args numGivenArgs <> " as if its type was:"
516 "But you are giving it " <> H.args numGivenArgs <> " as if its type was:"
@@ -390,16 +524,16 @@ toMismatchReport source localizer exprRegion thing tipe expected =
391 thisFunction =
525 thisFunction =
392 case maybeName of
526 case maybeName of
393− C.NoName ->
527+ NoName ->
394 "This function"
528 "This function"
396− C.FuncName name ->
530+ FuncName name ->
397 "The `" <> N.toString name <> "` function"
531 "The `" <> N.toString name <> "` function"
399− C.CtorName name ->
533+ CtorName name ->
400 "The `" <> N.toString name <> "` constructor"
534 "The `" <> N.toString name <> "` constructor"
402− C.OpName op ->
536+ OpName op ->
403 "The (" <> N.toString op <> ") function"
537 "The (" <> N.toString op <> ") function"
405 Report.toCodeSnippet source region (Just exprRegion)
539 Report.toCodeSnippet source region (Just exprRegion)
@@ -422,10 +556,10 @@ toMismatchReport source localizer exprRegion thing tipe expected =
425− C.RecordAccess field ->
559+ RecordAccess field ->
426 Report.toCodeSnippet source region (Just exprRegion) $
560 Report.toCodeSnippet source region (Just exprRegion) $
427− case Type.deepDealias tipe of
561+ case error "TODO figure out record things" tipe of
428− Can.TRecord _ _ ->
562+ Record _ _ ->
430 H.reflow $
564 H.reflow $
431 "This record does not have a `" <> N.toString field <> "` field:"
565 "This record does not have a `" <> N.toString field <> "` field:"
@@ -459,7 +593,7 @@ toMismatchReport source localizer exprRegion thing tipe expected =
462− Can.TLambda _ _ ->
596+ Lambda _ _ ->
464 H.reflow $
598 H.reflow $
465 "I cannot access field `" <> N.toString field <> "` of this " <> whatever <> ":"
599 "I cannot access field `" <> N.toString field <> "` of this " <> whatever <> ":"
@@ -484,9 +618,9 @@ toMismatchReport source localizer exprRegion thing tipe expected =
487− C.RecordUpdate ->
621+ RecordUpdate ->
488− case Type.deepDealias tipe of
622+ case error "TODO figure out record things" tipe of
489− Can.TRecord _ _ ->
623+ Record _ _ ->
490 Report.toCodeSnippet source region Nothing
624 Report.toCodeSnippet source region Nothing
492 H.reflow $
626 H.reflow $
@@ -507,15 +641,29 @@ toMismatchReport source localizer exprRegion thing tipe expected =
510− C.Destructure ->
644+ Destructure ->
511 error "TODO Destructure"
645 error "TODO Destructure"
652+countArgs :: Type -> Int
515-- OP LEFT
663-- OP LEFT
518−opLeftToDocs :: Type.Localizer -> Thing -> N.Name -> Can.Type -> Can.Type -> (H.Doc, H.Doc)
666+opLeftToDocs :: Localizer -> Thing -> N.Name -> Type -> Type -> (H.Doc, H.Doc)
519opLeftToDocs localizer thing op tipe expectedType =
667opLeftToDocs localizer thing op tipe expectedType =
520 case op of
668 case op of
@@ -533,10 +681,10 @@ opLeftToDocs localizer thing op tipe expectedType =
533 "//" -> badIDiv localizer "left" tipe
681 "//" -> badIDiv localizer "left" tipe
534 "&&" -> badBool localizer "&&" "left" tipe
682 "&&" -> badBool localizer "&&" "left" tipe
535 "||" -> badBool localizer "||" "left" tipe
683 "||" -> badBool localizer "||" "left" tipe
536− "<" -> badCompArg localizer thing "<" "left" tipe
684+ "<" -> badCompLeft localizer thing "<" "left" tipe
537− ">" -> badCompArg localizer thing ">" "left" tipe
685+ ">" -> badCompLeft localizer thing ">" "left" tipe
538− "<=" -> badCompArg localizer thing "<=" "left" tipe
686+ "<=" -> badCompLeft localizer thing "<=" "left" tipe
539− ">=" -> badCompArg localizer thing ">=" "left" tipe
687+ ">=" -> badCompLeft localizer thing ">=" "left" tipe
542 ( "The left side of (<|) needs to be a function so I can pipe arguments to it!"
690 ( "The left side of (<|) needs to be a function so I can pipe arguments to it!"
@@ -548,7 +696,7 @@ opLeftToDocs localizer thing op tipe expectedType =
548 , error "TODO"
696 , error "TODO"
550 case category of
698 case category of
551− C.Call ->
699+ Call ->
552 "Maybe you gave " <> funcName <> " too many arguments already?"
700 "Maybe you gave " <> funcName <> " too many arguments already?"
@@ -577,44 +725,53 @@ opLeftToDocs localizer thing op tipe expectedType =
577-- OP RIGHT
725-- OP RIGHT
729+ = EmphBoth (H.Doc, H.Doc)
730+ | EmphRight (H.Doc, H.Doc)
580−opRightToDocs :: Type.Localizer -> Thing -> N.Name -> Can.Type -> Can.Type -> (H.Doc, H.Doc)
733+opRightToDocs :: Localizer -> Thing -> N.Name -> Type -> Type -> RightDocs
581opRightToDocs localizer thing op tipe expectedType =
734opRightToDocs localizer thing op tipe expectedType =
582 case op of
735 case op of
584 | isInt tipe -> badCast op FloatInt
737 | isInt tipe -> badCast op FloatInt
585 | isFloat tipe -> badCast op IntFloat
738 | isFloat tipe -> badCast op IntFloat
586− | isString tipe -> badStringAdd
739+ | isString tipe -> EmphRight $ badStringAdd
587− | isList tipe -> badListAdd localizer "right" tipe
740+ | isList tipe -> EmphRight $ badListAdd localizer "right" tipe
588− | otherwise -> badMath localizer "Addition" "right" "+" tipe []
741+ | otherwise -> EmphRight $ badMath localizer "Addition" "right" "+" tipe []
591 | isInt tipe -> badCast op FloatInt
744 | isInt tipe -> badCast op FloatInt
592 | isFloat tipe -> badCast op IntFloat
745 | isFloat tipe -> badCast op IntFloat
593− | isList tipe -> badListMul localizer "right" tipe
746+ | isList tipe -> EmphRight $ badListMul localizer "right" tipe
594− | otherwise -> badMath localizer "Multiplication" "right" "*" tipe []
747+ | otherwise -> EmphRight $ badMath localizer "Multiplication" "right" "*" tipe []
597 | isInt tipe -> badCast op FloatInt
750 | isInt tipe -> badCast op FloatInt
598 | isFloat tipe -> badCast op IntFloat
751 | isFloat tipe -> badCast op IntFloat
599− | otherwise -> badMath localizer "Subtraction" "right" "-" tipe []
752+ | otherwise -> EmphRight $ badMath localizer "Subtraction" "right" "-" tipe []
602 | isInt tipe -> badCast op FloatInt
755 | isInt tipe -> badCast op FloatInt
603 | isFloat tipe -> badCast op IntFloat
756 | isFloat tipe -> badCast op IntFloat
604− | otherwise -> badMath localizer "Exponentiation" "right" "^" tipe []
757+ | otherwise -> EmphRight $ badMath localizer "Exponentiation" "right" "^" tipe []
606− "/" -> badFDiv localizer "right" tipe
759+ "/" -> EmphRight $ badFDiv localizer "right" tipe
607− "//" -> badIDiv localizer "right" tipe
760+ "//" -> EmphRight $ badIDiv localizer "right" tipe
608− "&&" -> badBool localizer "&&" "right" tipe
761+ "&&" -> EmphRight $ badBool localizer "&&" "right" tipe
609− "||" -> badBool localizer "||" "right" tipe
762+ "||" -> EmphRight $ badBool localizer "||" "right" tipe
610− "<" -> badCompRight localizer thing "<" tipe expectedType
763+ "<" -> badCompRight localizer "<" tipe expectedType
611− ">" -> badCompRight localizer thing ">" tipe expectedType
764+ ">" -> badCompRight localizer ">" tipe expectedType
612− "<=" -> badCompRight localizer thing "<=" tipe expectedType
765+ "<=" -> badCompRight localizer "<=" tipe expectedType
613− ">=" -> badCompRight localizer thing ">=" tipe expectedType
766+ ">=" -> badCompRight localizer ">=" tipe expectedType
614 "==" -> badEquality localizer "==" tipe expectedType
767 "==" -> badEquality localizer "==" tipe expectedType
615 "/=" -> badEquality localizer "/=" tipe expectedType
768 "/=" -> badEquality localizer "/=" tipe expectedType
771+ error "TODO see if people want ++ instead?"
619 H.reflow $
776 H.reflow $
620 "I cannot pipe this " <> whatever <> " in as the final argument:"
777 "I cannot pipe this " <> whatever <> " in as the final argument:"
@@ -633,7 +790,8 @@ opRightToDocs localizer thing op tipe expectedType =
635 case (tipe, expectedType) of
792 case (tipe, expectedType) of
636− (Can.TLambda expectedArgType _, Can.TLambda argType _) ->
793+ (Lambda expectedArgType _, Lambda argType _) ->
638 "I cannot pipe the argument through to this function:"
796 "I cannot pipe the argument through to this function:"
@@ -647,10 +805,10 @@ opRightToDocs localizer thing op tipe expectedType =
647 Nothing ->
805 Nothing ->
648 "But (|>) is piping it a function that expects the next argument to be:"
806 "But (|>) is piping it a function that expects the next argument to be:"
650− Just (C.FuncName name) ->
808+ Just (FuncName name) ->
651 "But (|>) is piping it to `" <> N.toString name <> "` which expects the next argument to be:"
809 "But (|>) is piping it to `" <> N.toString name <> "` which expects the next argument to be:"
653− Just (C.OpName op) ->
811+ Just (OpName op) ->
654 "But (|>) is piping it to (" <> N.toString op <> ") which expects the next argument to be:"
812 "But (|>) is piping it to (" <> N.toString op <> ") which expects the next argument to be:"
@@ -661,6 +819,7 @@ opRightToDocs localizer thing op tipe expectedType =
665 "The right side of (|>) needs to be a function so I can pipe arguments to it!"
824 "The right side of (|>) needs to be a function so I can pipe arguments to it!"
@@ -681,6 +840,7 @@ opRightToDocs localizer thing op tipe expectedType =
685 H.reflow $
845 H.reflow $
686 "The right argument of (" <> N.toString op <> ") is causing problems."
846 "The right argument of (" <> N.toString op <> ") is causing problems."
@@ -702,40 +862,40 @@ opRightToDocs localizer thing op tipe expectedType =
705−isInt :: Can.Type -> Bool
865+isInt :: Type -> Bool
706isInt tipe =
866isInt tipe =
707 case tipe of
867 case tipe of
708− Can.TType home name [] ->
868+ Type home name [] ->
709 home == ModuleName.basics && name == N.int
869 home == ModuleName.basics && name == N.int
715−isFloat :: Can.Type -> Bool
875+isFloat :: Type -> Bool
716isFloat tipe =
876isFloat tipe =
717 case tipe of
877 case tipe of
718− Can.TType home name [] ->
878+ Type home name [] ->
719 home == ModuleName.basics && name == N.float
879 home == ModuleName.basics && name == N.float
725−isString :: Can.Type -> Bool
885+isString :: Type -> Bool
726isString tipe =
886isString tipe =
727 case tipe of
887 case tipe of
728− Can.TType home name [] ->
888+ Type home name [] ->
729 home == ModuleName.string && name == N.string
889 home == ModuleName.string && name == N.string
735−isList :: Can.Type -> Bool
895+isList :: Type -> Bool
736isList tipe =
896isList tipe =
737 case tipe of
897 case tipe of
738− Can.TType home name [_] ->
898+ Type home name [_] ->
739 home == ModuleName.list && name == N.list
899 home == ModuleName.list && name == N.list
@@ -754,25 +914,26 @@ whatever =
754data ThisThenThat = FloatInt | IntFloat
914data ThisThenThat = FloatInt | IntFloat
757−badCast :: N.Name -> ThisThenThat -> (H.Doc, H.Doc)
917+badCast :: N.Name -> ThisThenThat -> RightDocs
758badCast op thisThenThat =
918badCast op thisThenThat =
760− H.text $
921+ H.text $
761− "I need both sides of (" <> N.toString op <> ") to be the exact same type. Both Int or both Float."
922+ "I need both sides of (" <> N.toString op <> ") to be the exact same type. Both Int or both Float."
764− anInt = ["an", H.dullyellow "Int"]
925+ anInt = ["an", H.dullyellow "Int"]
765− aFloat = ["a", H.dullyellow "Float"]
926+ aFloat = ["a", H.dullyellow "Float"]
766− toFloat = H.green "toFloat"
927+ toFloat = H.green "toFloat"
767− round = H.green "round"
928+ round = H.green "round"
769− case thisThenThat of
930+ case thisThenThat of
770− FloatInt ->
931+ FloatInt ->
771− badCastHelp aFloat anInt round toFloat
932+ badCastHelp aFloat anInt round toFloat
773− IntFloat ->
934+ IntFloat ->
774− badCastHelp anInt aFloat toFloat round
935+ badCastHelp anInt aFloat toFloat round
778badCastHelp :: [H.Doc] -> [H.Doc] -> H.Doc -> H.Doc -> H.Doc
939badCastHelp :: [H.Doc] -> [H.Doc] -> H.Doc -> H.Doc -> H.Doc
@@ -808,7 +969,7 @@ badStringAdd =
811−badListAdd :: Type.Localizer -> String -> Can.Type -> (H.Doc, H.Doc)
972+badListAdd :: Localizer -> String -> Type -> (H.Doc, H.Doc)
812badListAdd localizer direction tipe =
973badListAdd localizer direction tipe =
814 "I cannot do addition with lists:"
975 "I cannot do addition with lists:"
@@ -827,7 +988,7 @@ badListAdd localizer direction tipe =
830−badListMul :: Type.Localizer -> String -> Can.Type -> (H.Doc, H.Doc)
991+badListMul :: Localizer -> String -> Type -> (H.Doc, H.Doc)
831badListMul localizer direction tipe =
992badListMul localizer direction tipe =
832 badMath localizer "Multiplication" direction "*" tipe
993 badMath localizer "Multiplication" direction "*" tipe
@@ -839,7 +1000,7 @@ badListMul localizer direction tipe =
842−badMath :: Type.Localizer -> String -> String -> String -> Can.Type -> [H.Doc] -> (H.Doc, H.Doc)
1003+badMath :: Localizer -> String -> String -> String -> Type -> [H.Doc] -> (H.Doc, H.Doc)
843badMath localizer operation direction op tipe otherHints =
1004badMath localizer operation direction op tipe otherHints =
845 H.reflow $
1006 H.reflow $
@@ -859,7 +1020,7 @@ badMath localizer operation direction op tipe otherHints =
862−badFDiv :: Type.Localizer -> H.Doc -> Can.Type -> (H.Doc, H.Doc)
1023+badFDiv :: Localizer -> H.Doc -> Type -> (H.Doc, H.Doc)
863badFDiv localizer direction tipe =
1024badFDiv localizer direction tipe =
865 H.reflow $
1026 H.reflow $
@@ -892,7 +1053,7 @@ badFDiv localizer direction tipe =
895−badIDiv :: Type.Localizer -> H.Doc -> Can.Type -> (H.Doc, H.Doc)
1056+badIDiv :: Localizer -> H.Doc -> Type -> (H.Doc, H.Doc)
896badIDiv localizer direction tipe =
1057badIDiv localizer direction tipe =
898 H.reflow $
1059 H.reflow $
@@ -931,7 +1092,7 @@ badIDiv localizer direction tipe =
931-- BAD BOOLS
1092-- BAD BOOLS
934−badBool :: Type.Localizer -> H.Doc -> H.Doc -> Can.Type -> (H.Doc, H.Doc)
1095+badBool :: Localizer -> H.Doc -> H.Doc -> Type -> (H.Doc, H.Doc)
935badBool localizer op direction tipe =
1096badBool localizer op direction tipe =
937 H.reflow $
1098 H.reflow $
@@ -954,18 +1115,8 @@ badBool localizer op direction tipe =
954-- BAD COMPARISON
1115-- BAD COMPARISON
957−badCompRight :: Type.Localizer -> Thing -> String -> Can.Type -> Can.Type -> (H.Doc, H.Doc)
958−badCompRight localizer thing op tipe expectedType =
960− Can.TVar name | N.startsWith "comparable" name ->
961− badCompArg localizer thing op "right" tipe
964− badCompMix localizer op tipe expectedType
967−badCompArg :: Type.Localizer -> Thing -> String -> String -> Can.Type -> (H.Doc, H.Doc)
1118+badCompLeft :: Localizer -> Thing -> String -> String -> Type -> (H.Doc, H.Doc)
968−badCompArg localizer thing op direction tipe =
1119+badCompLeft localizer thing op direction tipe =
970 H.reflow $
1121 H.reflow $
971 "I cannot do a comparison with this value:"
1122 "I cannot do a comparison with this value:"
@@ -988,51 +1139,81 @@ badCompArg localizer thing op direction tipe =
991−badCompMix :: Type.Localizer -> String -> Can.Type -> Can.Type -> (H.Doc, H.Doc)
1142+badCompRight :: Localizer -> String -> Type -> Type -> RightDocs
992−badCompMix localizer op tipe expectedType =
1143+badCompRight localizer op tipe expectedType =
994− H.reflow $
1146+ H.reflow $
995− "I need both sides of (" <> op <> ") to be the same type:"
1147+ "I need both sides of (" <> op <> ") to be the same type:"
997− typeComparison localizer expectedType tipe
1149+ typeComparison localizer expectedType tipe
999− "The left side of is:"
1151+ "The left side of is:"
1001− "But the right side is:"
1153+ "But the right side is:"
1003− [ H.reflow $
1155+ [ H.reflow $
1004− "I cannot compare different types though! Which side of (" <> op <> ") is the problem?"
1156+ "I cannot compare different types though! Which side of (" <> op <> ") is the problem?"
1011-- BAD EQUALITY
1163-- BAD EQUALITY
1014−badEquality :: Type.Localizer -> String -> Can.Type -> Can.Type -> (H.Doc, H.Doc)
1166+badEquality :: Localizer -> String -> Type -> Type -> RightDocs
1015badEquality localizer op tipe expectedType =
1167badEquality localizer op tipe expectedType =
1017− H.reflow $
1170+ H.reflow $
1018− "I need both sides of (" <> op <> ") to be the same type:"
1171+ "I need both sides of (" <> op <> ") to be the same type:"
1020− typeComparison localizer expectedType tipe
1173+ typeComparison localizer expectedType tipe
1022− "The left side of is:"
1175+ "The left side of is:"
1024− "But the right side is:"
1177+ "But the right side is:"
1026− if isFloat tipe || isFloat expectedType then
1179+ if isFloat tipe || isFloat expectedType then
1027− [ H.toSimpleNote $
1180+ [ H.toSimpleNote $
1028− "Equality on floats is not 100% reliable due to the design of IEEE 754. I\
1181+ "Equality on floats is not 100% reliable due to the design of IEEE 754. I\
1029− \ recommend a check like (abs (x - y) < 0.0001) instead."
1182+ \ recommend a check like (abs (x - y) < 0.0001) instead."
1032− [ H.reflow $
1185+ [ H.reflow $
1033− "Different types can never be equal though! Which side is messed up?"
1186+ "Different types can never be equal though! Which side is messed up?"
1036−-- error "TODO detect problems here instead?"
1189+-- error "TODO detect problems here instead?"
1198+type Localizer = Map.Map N.Name ()
1201+typeComparison :: Localizer -> Type -> Type -> ( String, String, [H.Doc] ) -> H.Doc
1202+typeComparison localizer actual expected ( iAmSeeing, insteadOf, soHereAreSomeThoughts ) =
1204+ (actualDoc, expectedDoc) =
1205+ error "TODO diff" localizer actual expected
1208+ [ H.reflow iAmSeeing
1209+ , H.indent 4 actualDoc
1210+ , H.reflow insteadOf
1211+ , H.indent 4 expectedDoc
1213+ ++ soHereAreSomeThoughts
1216+indentType :: Localizer -> Type -> H.Doc
1217+indentType localizer tipe =
1218+ H.indent 4 (H.dullyellow (error "TODO Type.toDoc" localizer tipe))