@@ -12,6 +12,7 @@ import Prelude hiding (round)
12import Data.Monoid ((<>))
12import Data.Monoid ((<>))
14import qualified AST.Canonical as Can
14import qualified AST.Canonical as Can
15+import qualified AST.Module.Name as ModuleName
15import qualified AST.Utils.Type as Type
16import qualified AST.Utils.Type as Type
16import qualified Data.Index as Index
17import qualified Data.Index as Index
17import qualified Elm.Name as N
18import qualified Elm.Name as N
@@ -75,15 +76,24 @@ data Thing
76typeComparison :: Type.Localizer -> Can.Type -> Can.Type -> ( String, String, [H.Doc] ) -> H.Doc
77typeComparison :: Type.Localizer -> Can.Type -> Can.Type -> ( String, String, [H.Doc] ) -> H.Doc
77typeComparison localizer actual expected ( iAmSeeing, insteadOf, soHereAreSomeThoughts ) =
78typeComparison localizer actual expected ( iAmSeeing, insteadOf, soHereAreSomeThoughts ) =
80+ (actualDoc, expectedDoc) =
81+ Type.diffToDocs localizer actual expected
79 [ H.reflow iAmSeeing
84 [ H.reflow iAmSeeing
80− , H.indent 4 (Type.toDoc localizer actual)
85+ , H.indent 4 actualDoc
81 , H.reflow insteadOf
86 , H.reflow insteadOf
82− , H.indent 4 (Type.toDoc localizer expected)
87+ , H.indent 4 expectedDoc
84 ++ soHereAreSomeThoughts
89 ++ soHereAreSomeThoughts
92+indentType :: Type.Localizer -> Can.Type -> H.Doc
93+indentType localizer tipe =
94+ H.indent 4 (H.dullyellow (Type.toDoc localizer tipe))
87toDescription :: Thing -> String -> String
97toDescription :: Thing -> String -> String
88toDescription thing thatThingIs =
98toDescription thing thatThingIs =
89 case thing of
99 case thing of
@@ -210,7 +220,7 @@ toMismatchReport source localizer exprRegion thing tipe expected =
212 [ H.reflow $ toDescription thing "It is"
222 [ H.reflow $ toDescription thing "It is"
213− , Type.toDoc localizer tipe
223+ , indentType localizer tipe
214 , H.fillSep
224 , H.fillSep
215 ["But","I","only","now","how","to","negate"
225 ["But","I","only","now","how","to","negate"
216 ,H.dullyellow "Int","and",H.dullyellow "Float","values."
226 ,H.dullyellow "Int","and",H.dullyellow "Float","values."
@@ -234,7 +244,7 @@ toMismatchReport source localizer exprRegion thing tipe expected =
236 [ H.reflow $ toDescription thing "It is"
246 [ H.reflow $ toDescription thing "It is"
237− , Type.toDoc localizer tipe
247+ , indentType localizer tipe
238 , H.fillSep ["But","I","need","this","`if`","condition","to","be","a",H.dullyellow "Bool","value."]
248 , H.fillSep ["But","I","need","this","`if`","condition","to","be","a",H.dullyellow "Bool","value."]
239 , H.toSimpleHint $
249 , H.toSimpleHint $
240 "Elm does not have “truthiness” such that ints and strings and lists\
250 "Elm does not have “truthiness” such that ints and strings and lists\
@@ -423,7 +433,7 @@ toMismatchReport source localizer exprRegion thing tipe expected =
423 H.stack $
433 H.stack $
424 [ H.reflow $
434 [ H.reflow $
425 "It is a record with this type:"
435 "It is a record with this type:"
426− , Type.toDoc localizer tipe
436+ , indentType localizer tipe
427 , H.reflow $
437 , H.reflow $
428 "So maybe the ." <> N.toString field <> " field access is misspelled?"
438 "So maybe the ." <> N.toString field <> " field access is misspelled?"
@@ -457,7 +467,7 @@ toMismatchReport source localizer exprRegion thing tipe expected =
458 [ H.reflow $
468 [ H.reflow $
459 "The " <> whatever <> " is not a record! It is actually a function:"
469 "The " <> whatever <> " is not a record! It is actually a function:"
460− , Type.toDoc localizer tipe
470+ , indentType localizer tipe
461 , H.toSimpleHint "Maybe it is missing some arguments?"
471 , H.toSimpleHint "Maybe it is missing some arguments?"
@@ -470,7 +480,7 @@ toMismatchReport source localizer exprRegion thing tipe expected =
471 [ H.reflow $
481 [ H.reflow $
472 "The " <> whatever <> " is not a record though! It is a:"
482 "The " <> whatever <> " is not a record though! It is a:"
473− , Type.toDoc localizer tipe
483+ , indentType localizer tipe
@@ -493,7 +503,7 @@ toMismatchReport source localizer exprRegion thing tipe expected =
494 [ H.reflow $
504 [ H.reflow $
495 "I can only update records, but this appears to be a " <> whatever <> ":"
505 "I can only update records, but this appears to be a " <> whatever <> ":"
496− , Type.toDoc localizer tipe
506+ , indentType localizer tipe
@@ -534,7 +544,7 @@ opLeftToDocs localizer thing op tipe expectedType =
535 [ H.reflow $
545 [ H.reflow $
536 "Instead of a function, I am seeing " <> whatever <> ":"
546 "Instead of a function, I am seeing " <> whatever <> ":"
537− , Type.toDoc localizer tipe
547+ , indentType localizer tipe
538 , error "TODO"
548 , error "TODO"
540 case category of
550 case category of
@@ -657,7 +667,7 @@ opRightToDocs localizer thing op tipe expectedType =
658 [ H.reflow $
668 [ H.reflow $
659 "Instead of a function, I am seeing " <> whatever <> ":"
669 "Instead of a function, I am seeing " <> whatever <> ":"
660− , Type.toDoc localizer tipe
670+ , indentType localizer tipe
661 , error "TODO"
671 , error "TODO"
663 case category of
673 case category of
@@ -694,22 +704,42 @@ opRightToDocs localizer thing op tipe expectedType =
695isInt :: Can.Type -> Bool
705isInt :: Can.Type -> Bool
696isInt tipe =
706isInt tipe =
697− error "TODO isInt" tipe
707+ case tipe of
708+ Can.TType home name [] ->
709+ home == ModuleName.basics && name == N.int
700isFloat :: Can.Type -> Bool
715isFloat :: Can.Type -> Bool
701isFloat tipe =
716isFloat tipe =
702− error "TODO isFloat" tipe
717+ case tipe of
718+ Can.TType home name [] ->
719+ home == ModuleName.basics && name == N.float
705isString :: Can.Type -> Bool
725isString :: Can.Type -> Bool
706isString tipe =
726isString tipe =
707− error "TODO isString" tipe
727+ case tipe of
728+ Can.TType home name [] ->
729+ home == ModuleName.string && name == N.string
710isList :: Can.Type -> Bool
735isList :: Can.Type -> Bool
711isList tipe =
736isList tipe =
712− error "TODO isList" tipe
737+ case tipe of
738+ Can.TType home name [_] ->
739+ home == ModuleName.list && name == N.list
715whatever :: String
745whatever :: String
@@ -786,7 +816,7 @@ badListAdd localizer direction tipe =
787 [ H.reflow $
817 [ H.reflow $
788 "The " <> direction <> " side of (+) is " <> whatever <> ":"
818 "The " <> direction <> " side of (+) is " <> whatever <> ":"
789− , Type.toDoc localizer tipe
819+ , indentType localizer tipe
790 , H.fillSep
820 , H.fillSep
791 ["But","(+)","only","works","with",H.dullyellow "Int","and",H.dullyellow "Float","values."
821 ["But","(+)","only","works","with",H.dullyellow "Int","and",H.dullyellow "Float","values."
@@ -818,7 +848,7 @@ badMath localizer operation direction op tipe otherHints =
818 H.stack $
848 H.stack $
819 [ H.reflow $
849 [ H.reflow $
820 "The " <> direction <> " side of (" <> op <> ") is a " <> whatever <> ":"
850 "The " <> direction <> " side of (" <> op <> ") is a " <> whatever <> ":"
821− , Type.toDoc localizer tipe
851+ , indentType localizer tipe
822 , H.fillSep
852 , H.fillSep
823 ["But","(" <> H.text op <> ")","only","works","with"
853 ["But","(" <> H.text op <> ")","only","works","with"
824 ,H.dullyellow "Int","and",H.dullyellow "Float","values."
854 ,H.dullyellow "Int","and",H.dullyellow "Float","values."
@@ -857,7 +887,7 @@ badFDiv localizer direction tipe =
857 ,H.dullyellow "Float" <> ","
887 ,H.dullyellow "Float" <> ","
858 ,"but","instead","I","am","seeing:"
888 ,"but","instead","I","am","seeing:"
860− , Type.toDoc localizer tipe
890+ , indentType localizer tipe
@@ -892,7 +922,7 @@ badIDiv localizer direction tipe =
892 ,H.dullyellow "Int" <> ","
922 ,H.dullyellow "Int" <> ","
893 ,"but","instead","I","am","seeing:"
923 ,"but","instead","I","am","seeing:"
895− , Type.toDoc localizer tipe
925+ , indentType localizer tipe
@@ -912,7 +942,7 @@ badBool localizer op direction tipe =
912 ["Both","sides","of","(" <> op <> ")","must","be"
942 ["Both","sides","of","(" <> op <> ")","must","be"
913 ,H.dullyellow "Bool","values,","but","the",direction,"side","is:"
943 ,H.dullyellow "Bool","values,","but","the",direction,"side","is:"
915− , Type.toDoc localizer tipe
945+ , indentType localizer tipe
916 , H.toSimpleHint
946 , H.toSimpleHint
917 "Elm does not have “truthiness” such that ints and strings and lists are\
947 "Elm does not have “truthiness” such that ints and strings and lists are\
918 \ automatically converted to booleans. Do that conversion explicitly!"
948 \ automatically converted to booleans. Do that conversion explicitly!"
@@ -943,7 +973,7 @@ badCompArg localizer thing op direction tipe =
944 [ H.reflow $ toDescription thing $
974 [ H.reflow $ toDescription thing $
945 "The " <> direction <> " side of (" <> op <> ") is"
975 "The " <> direction <> " side of (" <> op <> ") is"
946− , Type.toDoc localizer tipe
976+ , indentType localizer tipe
947 , H.fillSep
977 , H.fillSep
948 ["But","(" <> H.text op <> ")","only","works","on"
978 ["But","(" <> H.text op <> ")","only","works","on"
949 ,H.dullyellow "Int" <> ","
979 ,H.dullyellow "Int" <> ","