@@ -26,6 +26,7 @@ import Data.Monoid ((<>))
26import qualified AST.Canonical as Can
26import qualified AST.Canonical as Can
27import qualified Data.Index as Index
27import qualified Data.Index as Index
28import qualified Elm.Name as N
28import qualified Elm.Name as N
29+import qualified Reporting.Annotation as A
29import qualified Reporting.Doc as D
30import qualified Reporting.Doc as D
30import qualified Reporting.Region as R
31import qualified Reporting.Region as R
31import qualified Reporting.Render.Code as Code
32import qualified Reporting.Render.Code as Code
@@ -66,7 +67,8 @@ data Context
66 | CallArity MaybeName Int
67 | CallArity MaybeName Int
67 | CallArg MaybeName Index.ZeroBased
68 | CallArg MaybeName Index.ZeroBased
68 | RecordAccess N.Name
69 | RecordAccess N.Name
69− | RecordUpdate N.Name (Map.Map N.Name Can.Expr)
70+ | RecordUpdateKeys N.Name (Map.Map N.Name Can.FieldUpdate)
71+ | RecordUpdateValue N.Name
70 | Destructure
72 | Destructure
@@ -384,7 +386,7 @@ addCategory thisIs category maybeAlias =
385 definitely whatever =
387 definitely whatever =
386 case maybeAlias of
388 case maybeAlias of
387− Just alias -> " a `" <> N.toString alias <> "` value:"
389+ Just alias -> " a `" <> N.toString alias <> "`:"
388 Nothing -> whatever
390 Nothing -> whatever
390 D.reflow $
392 D.reflow $
@@ -701,6 +703,10 @@ toExprReport source localizer exprRegion category tipe expected =
701 ( D.reflow problem
703 ( D.reflow problem
702 , loneType localizer tipe expectedType (addCategory thisIs category) furtherDetails
704 , loneType localizer tipe expectedType (addCategory thisIs category) furtherDetails
707+ custom maybeHighlight docPair =
708+ Report.Report "TYPE MISMATCH" exprRegion [] $
709+ Report.toCodeSnippet source region maybeHighlight docPair
705 case context of
711 case context of
706 ListEntry index ->
712 ListEntry index ->
@@ -731,18 +737,16 @@ toExprReport source localizer exprRegion category tipe expected =
733 OpLeft op ->
739 OpLeft op ->
734− Report.Report "TYPE MISMATCH" exprRegion [] $
735− Report.toCodeSnippet source region (Just exprRegion) $
740+ custom (Just exprRegion) $
736− opLeftToDocs localizer category op tipe expectedType
741+ opLeftToDocs localizer category op tipe expectedType
738 OpRight op ->
743 OpRight op ->
739− Report.Report "TYPE MISMATCH" exprRegion [] $
740− case opRightToDocs localizer category op tipe expectedType of
744+ case opRightToDocs localizer category op tipe expectedType of
741− EmphBoth details ->
745+ EmphBoth details ->
742− Report.toCodeSnippet source region Nothing details
746+ custom Nothing details
744− EmphRight details ->
748+ EmphRight details ->
745− Report.toCodeSnippet source region (Just exprRegion) details
749+ custom (Just exprRegion) details
747 IfCondition ->
751 IfCondition ->
@@ -862,34 +866,43 @@ toExprReport source localizer exprRegion category tipe expected =
865− RecordUpdate name updatedFields ->
869+ RecordUpdateKeys record expectedFields ->
867 case T.getFields tipe of
870 case T.getFields tipe of
868 Nothing ->
871 Nothing ->
869 ( Just exprRegion
873 ( Just exprRegion
870− , "I cannot update the `" <> N.toString name <> "` value:"
874+ , "This is not a record, so it has no fields to update!"
871 , "It is"
875 , "It is"
872− , [ D.reflow $ "It is not a record. It has no fields to update!"
876+ , [ D.reflow $ "But I need a record!"
876− Just _fields ->
880+ Just actualFields ->
877− case Map.keys updatedFields of
881+ case Map.foldrWithKey addLocatedField [] (Map.difference expectedFields actualFields) of
883+ error "TODO RecordUpdateKeys"
878− [field] ->
885+ A.At fieldRegion field : _ ->
879− ( Nothing
886+ badType
880− , "The `" <> N.toString name <> "` record does not have a `" <> N.toString field <> "` field."
888+ , "The `" <> N.toString record <> "` record does not have a `" <> N.toString field <> "` field:"
881− , "It is"
889+ , "The `" <> N.toString record <> "` is"
890+ , [ D.reflow $ "So maybe you want one of these fields instead? TODO make suggestions!"
882− , [ -- TODO suggest what the typo is!
891+ -- TODO suggest what the typo is!
886− _ ->
895+ RecordUpdateValue field ->
887− ( Nothing
896+ mismatch
888− , "The `" <> N.toString name <> "` record does have all of these fields:"
897+ ( Just exprRegion
889− , "It is"
898+ , "I cannot update the `" <> N.toString field <> "` field like this:"
890− , [ -- TODO suggest what the typo is!
899+ , "You are trying to update `" <> N.toString field <> "` to be"
900+ , singular "But it should be"
902+ "The record update syntax does not allow you to change the type of fields.\
903+ \ You can achieve that with record constructors or the record literal syntax."
894 Destructure ->
907 Destructure ->
@@ -902,7 +915,7 @@ toExprReport source localizer exprRegion category tipe expected =
905−-- COUNT ARGS
918+-- HELPERS
908countArgs :: T.Type -> Int
921countArgs :: T.Type -> Int
@@ -915,6 +928,11 @@ countArgs tipe =
931+addLocatedField :: N.Name -> Can.FieldUpdate -> [A.Located N.Name] -> [A.Located N.Name]
932+addLocatedField name (Can.FieldUpdate region _) names =
933+ A.At region name : names
919-- OP LEFT
937-- OP LEFT