on master help sign in
give a more helpful message on ambiguous exposed names
7f12297Evan Czaplicki
compiler/src/Reporting/Error/Canonicalize.hs+11−10
@@ -987,20 +987,21 @@ ambiguousName source region maybePrefix name possibleHomes thing =
987 Nothing ->
987 Nothing ->
988 let
988 let
989 homeToYellowDoc (ModuleName.Canonical _ home) =
989 homeToYellowDoc (ModuleName.Canonical _ home) =
990− D.dullyellow (D.fromName home)
990+ D.dullyellow (D.fromName home <> "." <> D.fromName name)
991−
992− bothOrAll =
993− if length possibleHomes == 2 then "both" else "all"
994 in
991 in
995 (
992 (
996− D.reflow $ "This usage of `" ++ Name.toChars name ++ "` is ambiguous."
993+ D.reflow $ "This usage of `" ++ Name.toChars name ++ "` is ambiguous:"
997 ,
994 ,
998 D.stack
995 D.stack
999 [ D.reflow $
996 [ D.reflow $
1000− "Check your imports. The following modules " ++ bothOrAll
997+ "This name is exposed by " ++ show (length possibleHomes) ++ " of your imports, so I am not\
1001− ++ " expose a `" ++ Name.toChars name ++ "` " ++ thing ++ ":"
998+ \ sure which one to use:"
1002 , D.indent 4 $ D.vcat $ map homeToYellowDoc possibleHomes
999 , D.indent 4 $ D.vcat $ map homeToYellowDoc possibleHomes
1003− , D.reflowLink "Read" "imports" "to learn how to clarify which one you want."
1000+ , D.reflow $
1001+ "I recommend using qualified names for imported values. I also recommend having\
1002+ \ at most one `exposing (..)` per file to make name clashes like this less common\
1003+ \ in the long run."
1004+ , D.link "Note" "Check out" "imports" "for more info on the import syntax."
1004 ]
1005 ]
1005 )
1006 )
1006
1007
@@ -1008,9 +1009,9 @@ ambiguousName source region maybePrefix name possibleHomes thing =
1008 let
1009 let
1009 homeToYellowDoc (ModuleName.Canonical _ home) =
1010 homeToYellowDoc (ModuleName.Canonical _ home) =
1010 if prefix == home then
1011 if prefix == home then
1011− D.blue "import" <+> D.dullyellow (D.fromName home)
1012+ D.cyan "import" <+> D.fromName home
1012 else
1013 else
1013− D.blue "import" <+> D.dullyellow (D.fromName home) <+> D.blue "as" <+> D.dullyellow (D.fromName prefix)
1014+ D.cyan "import" <+> D.fromName home <+> D.cyan "as" <+> D.fromName prefix
1014
1015
1015 eitherOrAny =
1016 eitherOrAny =
1016 if length possibleHomes == 2 then "either" else "any"
1017 if length possibleHomes == 2 then "either" else "any"