on master help sign in
Do a better job with hints when two known records clash
commit9eb52f1691c5d62980be3dc6b10f5ebf027227b9 authorEvan Czaplicki <evancz@users.noreply.github.com> dateWed 25 Apr 2018, 03:59 (9 years ago) parentbd99774
2 files changed+22−3
compiler/src/Reporting/Error/Type.hs+18 compiler/src/Type/Error.hs+4−3
compiler/src/Reporting/Error/Type.hs+18
@@ -481,6 +481,21 @@ problemToHint problem =
481481 T.Tuple _ _ _ -> badRigidSuper super "a tuple"
482482 T.Alias _ n _ _ -> badRigidSuper super ("a `" ++ N.toString n ++ "` value")
483483
484+ T.FieldsMissing fields ->
485+ case map (D.green . D.fromName) fields of
486+ [] ->
487+ []
488+
489+ [f1] ->
490+ [ D.toFancyHint ["Looks","like","the",f1,"field","is","missing."]
491+ ]
492+
493+ fieldDocs ->
494+ [ D.toFancyHint $
495+ ["Looks","like","fields"] ++ D.commaSep "and" id fieldDocs ++ ["are","missing."]
496+ ]
497+
498+
484499 T.FieldTypo typo possibilities ->
485500 case Suggest.sort (N.toString typo) N.toString possibilities of
486501 [] ->
@@ -492,6 +507,9 @@ problemToHint problem =
492507 ,D.dullyellow (D.fromName typo),"should","be"
493508 ,D.green (D.fromName nearest) <> "?"
494509 ]
510+ , D.toSimpleHint
511+ "Can more type annotations be added? Type annotations always help me give\
512+ \ more specific messages, and I think they could help a lot in this case!"
495513 ]
496514
497515
compiler/src/Type/Error.hs+4−3
@@ -185,6 +185,7 @@ data Problem
185185 | BadRigidVar N.Name Type
186186 | BadRigidSuper Super N.Name Type
187187 | FieldTypo N.Name [N.Name]
188+ | FieldsMissing [N.Name]
188189
189190
190191instance Functor Diff where
@@ -576,9 +577,9 @@ diffRecord localizer fields1 ext1 fields2 ext2 =
576577 case Map.lookupMin left of
577578 Just (f,_) -> Different $ Bag.one $ FieldTypo f (Map.keys fields2)
578579 Nothing ->
579− case Map.lookupMin right of
580− Just (f,_) -> Different $ Bag.one $ FieldTypo f (Map.keys fields1)
581− Nothing -> Similar
580+ if Map.null right
581+ then Similar
582+ else Different $ Bag.one $ FieldsMissing (Map.keys right)
582583
583584 (False, True) ->
584585 case Map.lookupMin left of