on master help sign in
Do a better job with hints when two known records clash
9eb52f1Evan Czaplicki
compiler/src/Reporting/Error/Type.hs+18
@@ -481,6 +481,21 @@ problemToHint problem =
481 T.Tuple _ _ _ -> badRigidSuper super "a tuple"
481 T.Tuple _ _ _ -> badRigidSuper super "a tuple"
482 T.Alias _ n _ _ -> badRigidSuper super ("a `" ++ N.toString n ++ "` value")
482 T.Alias _ n _ _ -> badRigidSuper super ("a `" ++ N.toString n ++ "` value")
483
483
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+
484 T.FieldTypo typo possibilities ->
499 T.FieldTypo typo possibilities ->
485 case Suggest.sort (N.toString typo) N.toString possibilities of
500 case Suggest.sort (N.toString typo) N.toString possibilities of
486 [] ->
501 [] ->
@@ -492,6 +507,9 @@ problemToHint problem =
492 ,D.dullyellow (D.fromName typo),"should","be"
507 ,D.dullyellow (D.fromName typo),"should","be"
493 ,D.green (D.fromName nearest) <> "?"
508 ,D.green (D.fromName nearest) <> "?"
494 ]
509 ]
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!"
495 ]
513 ]
496
514
497
515
compiler/src/Type/Error.hs+4−3
@@ -185,6 +185,7 @@ data Problem
185 | BadRigidVar N.Name Type
185 | BadRigidVar N.Name Type
186 | BadRigidSuper Super N.Name Type
186 | BadRigidSuper Super N.Name Type
187 | FieldTypo N.Name [N.Name]
187 | FieldTypo N.Name [N.Name]
188+ | FieldsMissing [N.Name]
188
189
189
190
190instance Functor Diff where
191instance Functor Diff where
@@ -576,9 +577,9 @@ diffRecord localizer fields1 ext1 fields2 ext2 =
576 case Map.lookupMin left of
577 case Map.lookupMin left of
577 Just (f,_) -> Different $ Bag.one $ FieldTypo f (Map.keys fields2)
578 Just (f,_) -> Different $ Bag.one $ FieldTypo f (Map.keys fields2)
578 Nothing ->
579 Nothing ->
579− case Map.lookupMin right of
580+ if Map.null right
581+ then Similar
580− Just (f,_) -> Different $ Bag.one $ FieldTypo f (Map.keys fields1)
582+ else Different $ Bag.one $ FieldsMissing (Map.keys right)
581− Nothing -> Similar
582
583
583 (False, True) ->
584 (False, True) ->
584 case Map.lookupMin left of
585 case Map.lookupMin left of