on master help sign in
improve style of errors for messed up type variables in aliases
commit9dac8bb10fa78c101a2065172fb65689945d3411 authorEvan Czaplicki <evancz@users.noreply.github.com> dateMon 19 Feb 2018, 16:23 (9 years ago) parenta82d1d4
1 file changed+27−9
src/Reporting/Error/Canonicalize.hs+27−9
src/Reporting/Error/Canonicalize.hs+27−9
@@ -794,9 +794,32 @@ toReport source err =
794794 let
795795 unused = map fst unusedVars
796796 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"
797+
798+ theseAreUsed =
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+
800823 in
801824 Report.Report "TYPE VARIABLE PROBLEMS" aliasRegion [] $
802825 Report.toCodeSnippet source aliasRegion Nothing
@@ -805,12 +828,7 @@ toReport source err =
805828 "Type alias `" <> N.toString typeName <> "` has some type variable problems."
806829 ,
807830 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!"]
831+ [ H.fillSep $ theseAreUsed ++ butTheseAreUnused
814832 , H.reflow $
815833 "My guess is that a definition like this will work better:"
816834 , H.indent 4 $ H.hsep $