@@ -37,7 +37,7 @@ data Error
3737 = Mismatch Mismatch
3838 | BadMain Type.Canonical
3939 | BadFlags Type.Canonical (Maybe Text)
40− | InfiniteType Text Type.Canonical
40+ | InfiniteType (Either Hint Text) Type.Canonical
4141
4242
4343data Mismatch = MismatchInfo
@@ -111,8 +111,8 @@ toReport localizer err =
111111 Mismatch info ->
112112 mismatchToReport localizer info
113113
114− InfiniteType name overallType ->
115− infiniteTypeToReport localizer name overallType
114+ InfiniteType context overallType ->
115+ infiniteTypeToReport localizer context overallType
116116
117117 BadMain tipe ->
118118 Report.report
@@ -960,25 +960,112 @@ padTypo arrow maxLen (missingField, knownField) =
960960-- INFINITE TYPES
961961
962962
963−infiniteTypeToReport
964− :: RenderType.Localizer
965− -> Text
966− -> Type.Canonical
967− -> Report.Report
968−infiniteTypeToReport localizer name overallType =
969− Report.report
970− "INFINITE TYPE"
971− Nothing
972− ( "I am inferring a weird self-referential type for " <> functionName name
973− )
974− ( stack
975− [ reflowParagraph $
976− "Here is my best effort at writing down the type. You will see ? and ∞ for\
977− \ parts of the type that repeat something already printed out infinitely."
978− , indent 4 (RenderType.toDoc localizer overallType)
979− , reflowParagraph $
980− "Usually staring at the type is not so helpful in these cases, so definitely\
981− \ read the debugging hints for ideas on how to figure this out: "
982− <> Help.hintLink "infinite-type"
983− ]
984− )
963+infiniteTypeToReport :: RenderType.Localizer -> Either Hint Text -> Type.Canonical -> Report.Report
964+infiniteTypeToReport localizer context overallType =
965+ let
966+ (maybeRegion, description) =
967+ case context of
968+ Right name ->
969+ ( Nothing, functionName name )
970+ Left hint ->
971+ infiniteHint hint
972+ in
973+ Report.report
974+ "INFINITE TYPE"
975+ maybeRegion
976+ ( "I am inferring a weird self-referential type for " <> description <> ":"
977+ )
978+ ( stack
979+ [ reflowParagraph $
980+ "Here is my best effort at writing down the type. You will see ∞ for\
981+ \ parts of the type that repeat something already printed out infinitely."
982+ , indent 4 (RenderType.toDoc localizer overallType)
983+ , reflowParagraph $
984+ "Usually staring at the type is not so helpful in these cases, so definitely\
985+ \ read the debugging hints for ideas on how to figure this out: "
986+ <> Help.hintLink "infinite-type"
987+ ]
988+ )
989+
990+
991+infiniteHint :: Hint -> (Maybe Region.Region, Text)
992+infiniteHint hint =
993+ case hint of
994+ CaseBranch n region ->
995+ ( Just region, "the " <> ordinalize n <> " `case` branch" )
996+
997+ Case ->
998+ ( Nothing, "this `case` expression" )
999+
1000+ IfCondition ->
1001+ ( Nothing, "the `if` condition" )
1002+
1003+ IfBranches ->
1004+ ( Nothing, "the `if` branches" )
1005+
1006+ MultiIfBranch n region ->
1007+ ( Just region, "the " <> ordinalize n <> " `if` branch" )
1008+
1009+ If ->
1010+ ( Nothing, "this `if` expression" )
1011+
1012+ List ->
1013+ ( Nothing, "this list" )
1014+
1015+ ListElement n region ->
1016+ ( Just region, "the " <> ordinalize n <> " list entry" )
1017+
1018+ BinopLeft _ region ->
1019+ ( Just region, "the left argument" )
1020+
1021+ BinopRight _ region ->
1022+ ( Just region, "the right argument" )
1023+
1024+ Binop _ ->
1025+ ( Nothing, "this expression" )
1026+
1027+ Function maybeName ->
1028+ ( Nothing, maybeFuncName maybeName )
1029+
1030+ UnexpectedArg maybeName 1 1 region ->
1031+ ( Just region, "the argument to " <> maybeFuncName maybeName )
1032+
1033+ UnexpectedArg maybeName index _total region ->
1034+ ( Just region, "the " <> ordinalize index <> " argument to " <> maybeFuncName maybeName )
1035+
1036+ FunctionArity maybeName _ _ region ->
1037+ ( Just region, maybeFuncName maybeName )
1038+
1039+ ReturnType name _ _ region ->
1040+ ( Just region, functionName name )
1041+
1042+ Instance name ->
1043+ ( Nothing, functionName name )
1044+
1045+ Literal name ->
1046+ ( Nothing, name )
1047+
1048+ Pattern _ ->
1049+ ( Nothing, "this pattern" )
1050+
1051+ Shader ->
1052+ ( Nothing, "this shader" )
1053+
1054+ Lambda ->
1055+ ( Nothing, "this anonymous function" )
1056+
1057+ Access _ _ ->
1058+ ( Nothing, "this field access" )
1059+
1060+ Record ->
1061+ ( Nothing, "this record" )
1062+
1063+ -- effect manager problems
1064+ Manager name ->
1065+ ( Nothing, functionName name )
1066+
1067+ State name ->
1068+ ( Nothing, functionName name )
1069+
1070+ SelfMsg ->
1071+ ( Nothing, "this code" )