on master help sign in
Finish TypeVarsMessedUpInAlias TODO!
8527e24Evan Czaplicki
src/Reporting/Error/Canonicalize.hs+24−16
@@ -776,9 +776,9 @@ toReport source err =
776 H.stack
776 H.stack
777 [ H.fillSep $
777 [ H.fillSep $
778 ["I","recommend","removing"] ++ stuff ++ ["from","the","declaration,","like","this:"]
778 ["I","recommend","removing"] ++ stuff ++ ["from","the","declaration,","like","this:"]
779− , H.indent 4 $ H.hsep $
779+ , H.indent 4 $ H.dullyellow $ H.hsep $
780 ["type","alias",H.nameToDoc typeName]
780 ["type","alias",H.nameToDoc typeName]
781− ++ map H.nameToDoc (filter (\v -> notElem v allUnusedNames) allVars)
781+ ++ map H.nameToDoc (filter (`notElem` allUnusedNames) allVars)
782 ++ ["=", "..."]
782 ++ ["=", "..."]
783 , H.reflow $
783 , H.reflow $
784 "Why? Well, if I allowed `type alias Height a = Float` I would need to answer\
784 "Why? Well, if I allowed `type alias Height a = Float` I would need to answer\
@@ -791,27 +791,35 @@ toReport source err =
791 unboundTypeVars source aliasRegion ["type","alias"] typeName allVars unbound unbounds
791 unboundTypeVars source aliasRegion ["type","alias"] typeName allVars unbound unbounds
792
792
793 (_, _) ->
793 (_, _) ->
794− error "TODO TypeVarsMessedUpInAlias"
794+ let
795− {-
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
796 Report.Report "TYPE VARIABLE PROBLEMS" aliasRegion [] $
801 Report.Report "TYPE VARIABLE PROBLEMS" aliasRegion [] $
797− Report.toCodeSnippet source region Nothing
802+ Report.toCodeSnippet source aliasRegion Nothing
798 (
803 (
799 H.reflow $
804 H.reflow $
800− "Type alias `" <> typeName <> "` has some type variable problems."
805+ "Type alias `" <> N.toString typeName <> "` has some type variable problems."
801 ,
806 ,
802 H.stack
807 H.stack
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!"]
803− [ H.reflow $
814+ , H.reflow $
804− "The definition uses certain type variables ("
815+ "My guess is that a definition like this will work better:"
805− <> H.commaSep unused <> ") but they do not appear in the aliased type. "
816+ , H.indent 4 $ H.hsep $
806− <> "Furthermore, the aliased type says it uses type variables ("
817+ ["type", "alias", H.nameToDoc typeName]
807− <> H.commaSep unbound
818+ ++ map H.nameToDoc (filter (`notElem` unused) allVars)
808− <> ") that do not appear in the declaration."
819+ ++ map (H.green . H.nameToDoc) unbound
809− , text "You probably need to change the declaration like this:"
820+ ++ ["=", "..."]
810− , H.dullyellow $ hsep $
811− map text ("type" : "alias" : typeName : filter (`notElem` unused) givenVars ++ unbound ++ ["=", "..."])
812 ]
821 ]
813 )
822 )
814− -}
815
823
816
824
817
825