on master help sign in
improve style of errors for messed up type variables in aliases
9dac8bbEvan Czaplicki
src/Reporting/Error/Canonicalize.hs+27−9
@@ -794,9 +794,32 @@ toReport source err =
794 let
794 let
795 unused = map fst unusedVars
795 unused = map fst unusedVars
796 unbound = map fst unboundVars
796 unbound = map fst unboundVars
797− var name = "`" <> H.nameToDoc name <> "`"
797+
798− isOrAre vars = if length vars == 1 then "is" else "are"
798+ theseAreUsed =
799− itOrThem vars = if length vars == 1 then "it" else "them"
799+ case unbound of
800+ [x] ->
801+ ["Type","variable",H.dullyellow ("`" <> H.nameToDoc x <> "`"),"appears"
802+ ,"in","the","definition,","but","I","do","not","see","it","declared."
803+ ]
804+
805+ _ ->
806+ ["Type","variables"]
807+ ++ H.commaSep "and" H.dullyellow (map H.nameToDoc unbound)
808+ ++ ["are","used","in","the","definition,","but","I","do","not","see","them","declared."]
809+
810+ butTheseAreUnused =
811+ case unused of
812+ [x] ->
813+ ["Likewise,","type","variable"
814+ ,H.dullyellow ("`" <> H.nameToDoc x <> "`")
815+ ,"is","delared,","but","not","used."
816+ ]
817+
818+ _ ->
819+ ["Likewise,","type","variables"]
820+ ++ H.commaSep "and" H.dullyellow (map H.nameToDoc unused)
821+ ++ ["are","delared,","but","not","used."]
822+
800 in
823 in
801 Report.Report "TYPE VARIABLE PROBLEMS" aliasRegion [] $
824 Report.Report "TYPE VARIABLE PROBLEMS" aliasRegion [] $
802 Report.toCodeSnippet source aliasRegion Nothing
825 Report.toCodeSnippet source aliasRegion Nothing
@@ -805,12 +828,7 @@ toReport source err =
805 "Type alias `" <> N.toString typeName <> "` has some type variable problems."
828 "Type alias `" <> N.toString typeName <> "` has some type variable problems."
806 ,
829 ,
807 H.stack
830 H.stack
808− [ H.fillSep $
831+ [ H.fillSep $ theseAreUsed ++ butTheseAreUnused
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 $
832 , H.reflow $
815 "My guess is that a definition like this will work better:"
833 "My guess is that a definition like this will work better:"
816 , H.indent 4 $ H.hsep $
834 , H.indent 4 $ H.hsep $