@@ -66,7 +66,7 @@ data Context
6666 | CaseBranch Index.ZeroBased
6767 | CallArity MaybeName Int
6868 | CallArg MaybeName Index.ZeroBased
69− | RecordAccess N.Name
69+ | RecordAccess R.Region (Maybe N.Name) R.Region N.Name
7070 | RecordUpdateKeys N.Name (Map.Map N.Name Can.FieldUpdate)
7171 | RecordUpdateValue N.Name
7272 | Destructure
@@ -805,30 +805,35 @@ toExprReport source localizer exprRegion category tipe expected =
805805 ]
806806 )
807807
808− RecordAccess field ->
808+ RecordAccess recordRegion maybeName fieldRegion field ->
809809 case T.iteratedDealias tipe of
810810 T.Record fields ext ->
811− custom (Just exprRegion)
811+ custom (Just fieldRegion)
812812 ( D.reflow $
813− "This record does not have a `" <> N.toString field <> "` field:"
813+ "This "
814+ <> maybe "" (\n -> "`" <> N.toString n <> "`") maybeName
815+ <> " record does not have a `" <> N.toString field <> "` field:"
814816 , case Suggest.sort (N.toString field) (N.toString . fst) (Map.toList fields) of
815817 [] ->
816818 D.reflow "In fact, it is a record with NO fields!"
817819
818820 f:fs ->
819821 D.stack
820− [ addAlias "record" tipe (\noun -> "It is a " <> noun <> " with fields:")
822+ [ D.reflow $
823+ "This is usually a typo. Here are the "
824+ <> maybe "" (\n -> "`" <> N.toString n <> "`") maybeName
825+ <> " fields that are most similar:"
821826 , toNearbyRecord localizer f fs ext
822827 , D.fillSep
823− ["So","instead","of",D.dullyellow (D.fromName field) <> ","
824− ,"maybe","you","want",D.green (D.fromName (fst f)) <> "?"
828+ ["So","maybe",D.dullyellow (D.fromName field)
829+ ,"should","be",D.green (D.fromName (fst f)) <> "?"
825830 ]
826831 ]
827832 )
828833
829834 _ ->
830835 badType
831− ( Just exprRegion
836+ ( Just recordRegion
832837 , "This is not a record, so it has no fields to access!"
833838 , "It is"
834839 , [ D.fillSep
@@ -869,11 +874,12 @@ toExprReport source localizer exprRegion category tipe expected =
869874
870875 f:fs ->
871876 D.stack
872− [ addAlias "record" tipe (\noun -> rStr <> " is a " <> noun <> " with fields:")
877+ [ D.reflow $
878+ "This is usually a typo. Here are the " <> rStr <> " fields that are most similar:"
873879 , toNearbyRecord localizer f fs ext
874880 , D.fillSep
875− ["So","instead","of",D.dullyellow (D.fromName field) <> ","
876− ,"maybe","you","want",D.green (D.fromName (fst f)) <> "?"
881+ ["So","maybe",D.dullyellow (D.fromName field)
882+ ,"should","be",D.green (D.fromName (fst f)) <> "?"
877883 ]
878884 ]
879885 )
@@ -923,16 +929,6 @@ countArgs tipe =
923929 0
924930
925931
926−addAlias :: String -> T.Type -> (String -> String) -> D.Doc
927−addAlias noun tipe toMessage =
928− case tipe of
929− T.Alias _ name _ _ ->
930− D.reflow (toMessage ("`" <> N.toString name <> "`"))
931−
932− _ ->
933− D.reflow (toMessage noun)
934−
935−
936932
937933-- FIELD NAME HELPERS
938934