@@ -73,7 +73,7 @@ data Error
73 | Shadowing N.Name R.Region R.Region
73 | Shadowing N.Name R.Region R.Region
74 | TupleLargerThanThree R.Region
74 | TupleLargerThanThree R.Region
75 | TypeVarsUnboundInUnion R.Region N.Name [N.Name] (N.Name, R.Region) [(N.Name, R.Region)]
75 | TypeVarsUnboundInUnion R.Region N.Name [N.Name] (N.Name, R.Region) [(N.Name, R.Region)]
76− | TypeVarsMessedUpInAlias R.Region N.Name [N.Name] [A.Located N.Name] [A.Located N.Name]
76+ | TypeVarsMessedUpInAlias R.Region N.Name [N.Name] [(N.Name, R.Region)] [(N.Name, R.Region)]
79data BadArityContext
79data BadArityContext
@@ -735,114 +735,133 @@ toReport source err =
738− TypeVarsUnboundInUnion unionRegion tipe allVars (unboundVar, varRegion) unboundVars ->
738+ TypeVarsUnboundInUnion unionRegion typeName allVars unbound unbounds ->
739− let
739+ unboundTypeVars source unionRegion ["type"] typeName allVars unbound unbounds
741− "`" <> H.nameToDoc name <> "`"
741+ TypeVarsMessedUpInAlias aliasRegion typeName allVars unusedVars unboundVars ->
742+ case (unusedVars, unboundVars) of
743+ (unused:unuseds, []) ->
746+ "`" <> H.nameToDoc name <> "`"
743− (title, subRegion, overview) =
751+ (title, subRegion, overview, stuff) =
744− case map fst unboundVars of
752+ case unuseds of
746− ( "UNBOUND TYPE VARIABLE"
754+ ("UNUSED TYPE VARIABLE"
747− , Just varRegion
755+ , Just (snd unused)
748− , ["The",backQuote tipe,"type","uses","an","unbound","type","variable"
756+ , ["Type","alias",backQuote typeName,"does","not","use","the"
757+ ,backQuote (fst unused),"type","variable."
749− ,H.dullyellow (backQuote unboundVar),"in","its","definition:"
759+ , [H.dullyellow (backQuote (fst unused))]
763+ ( "UNUSED TYPE VARIABLES"
765+ , ["Type","variables"]
766+ ++ H.commaSep "and" id (map H.nameToDoc allUnusedNames)
767+ ++ ["are","unused","in","the",backQuote typeName,"definition."]
768+ , H.commaSep "and" H.dullyellow (map H.nameToDoc allUnusedNames)
771+ Report.Report title aliasRegion [] $
772+ Report.toCodeSnippet source aliasRegion subRegion
778+ ["I","recommend","removing"] ++ stuff ++ ["from","the","declaration,","like","this:"]
779+ , H.indent 4 $ H.hsep $
780+ ["type","alias",H.nameToDoc typeName]
781+ ++ map H.nameToDoc (filter (\v -> notElem v allUnusedNames) allVars)
784+ "Why? Well, if I allowed `type alias Height a = Float` I would need to answer\
785+ \ some weird questions. Is `Height Bool` the same as `Float`? Is `Height Bool`\
786+ \ the same as `Height Int`? My solution is to not need to ask them!"
753− vars ->
790+ ([], unbound:unbounds) ->
754− ( "UNBOUND TYPE VARIABLES"
791+ unboundTypeVars source aliasRegion ["type","alias"] typeName allVars unbound unbounds
756− , ["Type","variables"]
793+ (_, _) ->
757− ++ H.commaSep "and" H.dullyellow (H.nameToDoc unboundVar : map H.nameToDoc vars)
794+ error "TODO TypeVarsMessedUpInAlias"
758− ++ ["are","unbound","in","the",backQuote tipe,"type","definition:"]
795+ {-
796+ Report.Report "TYPE VARIABLE PROBLEMS" aliasRegion [] $
797+ Report.toCodeSnippet source region Nothing
800+ "Type alias `" <> typeName <> "` has some type variable problems."
804+ "The definition uses certain type variables ("
805+ <> H.commaSep unused <> ") but they do not appear in the aliased type. "
806+ <> "Furthermore, the aliased type says it uses type variables ("
807+ <> H.commaSep unbound
808+ <> ") that do not appear in the declaration."
809+ , text "You probably need to change the declaration like this:"
810+ , H.dullyellow $ hsep $
811+ map text ("type" : "alias" : typeName : filter (`notElem` unused) givenVars ++ unbound ++ ["=", "..."])
761− Report.Report title unionRegion [] $
815+
762− Report.toCodeSnippet source unionRegion subRegion
816+
818+-- BAD TYPE VARIABLES
821+unboundTypeVars :: Code.Source -> R.Region -> [H.Doc] -> N.Name -> [N.Name] -> (N.Name, R.Region) -> [(N.Name, R.Region)] -> Report.Report
822+unboundTypeVars source declRegion tipe typeName allVars (unboundVar, varRegion) unboundVars =
825+ "`" <> H.nameToDoc name <> "`"
764− H.fillSep overview
827+ (title, subRegion, overview) =
768− "You probably need to change the type declaration to something like this:"
769− , H.indent 4 $ H.hsep $
770− ["type", H.nameToDoc tipe]
771− ++ map H.nameToDoc allVars
772− ++ map (H.green . H.nameToDoc) (unboundVar : map fst unboundVars)
828+ case map fst unboundVars of
773− ++ ["=", "..."]
829+ [] ->
774− , H.reflow $
830+ ( "UNBOUND TYPE VARIABLE"
775− "Why? Well, imagine one `" ++ N.toString tipe ++ "` where `" ++ N.toString unboundVar ++
831+ , Just varRegion
776− "` is an Int and another where it is a Bool. When we explicitly list the type\
832+ , ["The",backQuote typeName]
777− \ variables, the type checker can see that they are actually different types."
833+ ++ tipe
778− ]
834+ ++ ["uses","an","unbound","type","variable",H.dullyellow (backQuote unboundVar),"in","its","definition:"]
781− TypeVarsMessedUpInAlias _ _ _ _ _ ->
837+ vars ->
782− error "TODO TypeVarsMessedUpInAlias"
786−-- UnboundTypeVarsInUnion typeName givenVars unbound ->
787−-- unboundTypeVars "type" typeName givenVars unbound
789−-- UnboundTypeVarsInAlias typeName givenVars unbound ->
790−-- unboundTypeVars "type alias" typeName givenVars unbound
792−-- UnusedTypeVarsInAlias typeName givenVars unused ->
794−-- "UNUSED TYPE VARIABLES"
796−-- ( "Type alias `" <> typeName <> "` cannot have unused type variables: "
797−-- <> H.commaSep unused
800−-- [ text "You probably need to change the declaration like this:"
801−-- , H.dullyellow $ hsep $
802−-- map text ("type" : "alias" : typeName : filter (`notElem` unused) givenVars ++ ["=", "..."])
806−-- MessyTypeVarsInAlias typeName givenVars unused unbound ->
808−-- "TYPE VARIABLE PROBLEMS"
810−-- ( "Type alias `" <> typeName <> "` has some problems with type variables."
814−-- "The declaration says it uses certain type variables ("
815−-- <> H.commaSep unused <> ") but they do not appear in the aliased type. "
816−-- <> "Furthermore, the aliased type says it uses type variables ("
817−-- <> H.commaSep unbound
818−-- <> ") that do not appear in the declaration."
819−-- , text "You probably need to change the declaration like this:"
820−-- , H.dullyellow $ hsep $
821−-- map text ("type" : "alias" : typeName : filter (`notElem` unused) givenVars ++ unbound ++ ["=", "..."])
826−--unboundTypeVars :: Text -> Text -> [Text] -> [Text] -> Report.Report
827−--unboundTypeVars declKind typeName givenVars unboundVars =
829−-- "UNBOUND TYPE VARIABLES"
838+ ( "UNBOUND TYPE VARIABLES"
830−-- Nothing
839+ , Nothing
831−-- ( H.capitalize declKind <> " `" <> typeName <> "` must declare its use of type variable"
840+ , ["Type","variables"]
832−-- <> H.commaSep unboundVars
841+ ++ H.commaSep "and" H.dullyellow (H.nameToDoc unboundVar : map H.nameToDoc vars)
833−-- )
842+ ++ ["are","unbound","in","the",backQuote typeName] ++ tipe ++ ["definition:"]
845+ Report.Report title declRegion [] $
846+ Report.toCodeSnippet source declRegion subRegion
834−-- ( H.stack
850+ H.stack
835−-- [ text "You probably need to change the declaration like this:"
852+ "You probably need to change the declaration to something like this:"
836−-- , hsep $
853+ , H.indent 4 $ H.hsep $
837−-- map text (declKind : typeName : givenVars)
854+ tipe
855+ ++ [H.nameToDoc typeName]
856+ ++ map H.nameToDoc allVars
838−-- ++ map (H.dullyellow . text) unboundVars
857+ ++ map (H.green . H.nameToDoc) (unboundVar : map fst unboundVars)
839−-- ++ map text ["=", "..."]
858+ ++ ["=", "..."]
840−-- , reflow $
859+ , H.reflow $
841−-- "Here's why. Imagine one `" <> typeName <> "` where `" <> head unboundVars <>
860+ "Why? Well, imagine one `" ++ N.toString typeName ++ "` where `" ++ N.toString unboundVar ++
842−-- "` is an Int and another where it is a Bool. When we explicitly list the type\
861+ "` is an Int and another where it is a Bool. When we explicitly list the type\
843−-- \ variables, the type checker can see that they are actually different types."
862+ \ variables, the type checker can see that they are actually different types."
@@ -921,7 +940,6 @@ ambiguousName source region maybePrefix name possibleHomes thing =
925-- NOT FOUND
943-- NOT FOUND