@@ -66,7 +66,7 @@ data Context
66 | CaseBranch Index.ZeroBased
66 | CaseBranch Index.ZeroBased
67 | CallArity MaybeName Int
67 | CallArity MaybeName Int
68 | CallArg MaybeName Index.ZeroBased
68 | CallArg MaybeName Index.ZeroBased
69− | RecordAccess N.Name
69+ | RecordAccess R.Region (Maybe N.Name) R.Region N.Name
70 | RecordUpdateKeys N.Name (Map.Map N.Name Can.FieldUpdate)
70 | RecordUpdateKeys N.Name (Map.Map N.Name Can.FieldUpdate)
71 | RecordUpdateValue N.Name
71 | RecordUpdateValue N.Name
72 | Destructure
72 | Destructure
@@ -805,30 +805,35 @@ toExprReport source localizer exprRegion category tipe expected =
808− RecordAccess field ->
808+ RecordAccess recordRegion maybeName fieldRegion field ->
809 case T.iteratedDealias tipe of
809 case T.iteratedDealias tipe of
810 T.Record fields ext ->
810 T.Record fields ext ->
811− custom (Just exprRegion)
811+ custom (Just fieldRegion)
812 ( D.reflow $
812 ( D.reflow $
814+ <> maybe "" (\n -> "`" <> N.toString n <> "`") maybeName
813− "This record does not have a `" <> N.toString field <> "` field:"
815+ <> " record does not have a `" <> N.toString field <> "` field:"
814 , case Suggest.sort (N.toString field) (N.toString . fst) (Map.toList fields) of
816 , case Suggest.sort (N.toString field) (N.toString . fst) (Map.toList fields) of
816 D.reflow "In fact, it is a record with NO fields!"
818 D.reflow "In fact, it is a record with NO fields!"
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:"
821 , toNearbyRecord localizer f fs ext
826 , toNearbyRecord localizer f fs ext
822 , D.fillSep
827 , D.fillSep
823− ["So","instead","of",D.dullyellow (D.fromName field) <> ","
828+ ["So","maybe",D.dullyellow (D.fromName field)
824− ,"maybe","you","want",D.green (D.fromName (fst f)) <> "?"
829+ ,"should","be",D.green (D.fromName (fst f)) <> "?"
831− ( Just exprRegion
836+ ( Just recordRegion
832 , "This is not a record, so it has no fields to access!"
837 , "This is not a record, so it has no fields to access!"
833 , "It is"
838 , "It is"
834 , [ D.fillSep
839 , [ D.fillSep
@@ -869,11 +874,12 @@ toExprReport source localizer exprRegion category tipe expected =
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:"
873 , toNearbyRecord localizer f fs ext
879 , toNearbyRecord localizer f fs ext
874 , D.fillSep
880 , D.fillSep
875− ["So","instead","of",D.dullyellow (D.fromName field) <> ","
881+ ["So","maybe",D.dullyellow (D.fromName field)
876− ,"maybe","you","want",D.green (D.fromName (fst f)) <> "?"
882+ ,"should","be",D.green (D.fromName (fst f)) <> "?"
@@ -923,16 +929,6 @@ countArgs tipe =
926−addAlias :: String -> T.Type -> (String -> String) -> D.Doc
927−addAlias noun tipe toMessage =
929− T.Alias _ name _ _ ->
930− D.reflow (toMessage ("`" <> N.toString name <> "`"))
933− D.reflow (toMessage noun)
937-- FIELD NAME HELPERS
933-- FIELD NAME HELPERS