on master help sign in
Finish TypeVarsMessedUpInAlias TODO!
commit8527e24759ee14f73fd639366609229c93d9278f authorEvan Czaplicki <evancz@users.noreply.github.com> dateMon 19 Feb 2018, 16:03 (9 years ago) parent07712e9
1 file changed+24−16
src/Reporting/Error/Canonicalize.hs+24−16
src/Reporting/Error/Canonicalize.hs+24−16
@@ -776,9 +776,9 @@ toReport source err =
776776 H.stack
777777 [ H.fillSep $
778778 ["I","recommend","removing"] ++ stuff ++ ["from","the","declaration,","like","this:"]
779− , H.indent 4 $ H.hsep $
779+ , H.indent 4 $ H.dullyellow $ H.hsep $
780780 ["type","alias",H.nameToDoc typeName]
781− ++ map H.nameToDoc (filter (\v -> notElem v allUnusedNames) allVars)
781+ ++ map H.nameToDoc (filter (`notElem` allUnusedNames) allVars)
782782 ++ ["=", "..."]
783783 , H.reflow $
784784 "Why? Well, if I allowed `type alias Height a = Float` I would need to answer\
@@ -791,27 +791,35 @@ toReport source err =
791791 unboundTypeVars source aliasRegion ["type","alias"] typeName allVars unbound unbounds
792792
793793 (_, _) ->
794− error "TODO TypeVarsMessedUpInAlias"
795− {-
794+ let
795+ unused = map fst unusedVars
796+ unbound = map fst unboundVars
797+ var name = "`" <> H.nameToDoc name <> "`"
798+ isOrAre vars = if length vars == 1 then "is" else "are"
799+ itOrThem vars = if length vars == 1 then "it" else "them"
800+ in
796801 Report.Report "TYPE VARIABLE PROBLEMS" aliasRegion [] $
797− Report.toCodeSnippet source region Nothing
802+ Report.toCodeSnippet source aliasRegion Nothing
798803 (
799804 H.reflow $
800− "Type alias `" <> typeName <> "` has some type variable problems."
805+ "Type alias `" <> N.toString typeName <> "` has some type variable problems."
801806 ,
802807 H.stack
803− [ H.reflow $
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 ++ ["=", "..."])
808+ [ H.fillSep $
809+ ["The","definition","uses"]
810+ ++ H.commaSep "and" H.dullyellow (map var unbound)
811+ ++ ["but","I","do","not","see",itOrThem unbound,"declared.","Likewise,"]
812+ ++ H.commaSep "and" H.dullyellow (map var unused)
813+ ++ [isOrAre unused,"delared,","but","not","used!"]
814+ , H.reflow $
815+ "My guess is that a definition like this will work better:"
816+ , H.indent 4 $ H.hsep $
817+ ["type", "alias", H.nameToDoc typeName]
818+ ++ map H.nameToDoc (filter (`notElem` unused) allVars)
819+ ++ map (H.green . H.nameToDoc) unbound
820+ ++ ["=", "..."]
812821 ]
813822 )
814− -}
815823
816824
817825