on master help sign in
Make error messages nicer for rigid type variables
commite481f004729492fe08e87399ef504bd7b397259e authorEvan Czaplicki <evancz@users.noreply.github.com> dateTue 20 Sep 2016, 11:31 (10 years ago) parent4bec0ec
1 file changed+42−16
src/Reporting/Error/Type.hs+42−16
src/Reporting/Error/Type.hs+42−16
@@ -708,14 +708,14 @@ reasonToStringHelp reason =
708708 BadVar (Just CompAppend) _ ->
709709 go "Only strings and lists are both comparable and appendable."
710710
711− BadVar (Just (Rigid _)) (Just (Rigid _)) ->
712− go doubleRigidError
711+ BadVar (Just (Rigid maybeLeftName)) (Just (Rigid maybeRightName)) ->
712+ go $ doubleRigidError maybeLeftName maybeRightName
713713
714− BadVar (Just (Rigid _)) _ ->
715− go singleRigidError
714+ BadVar (Just (Rigid maybeName)) _ ->
715+ go $ singleRigidError maybeName
716716
717− BadVar _ (Just (Rigid _)) ->
718− go singleRigidError
717+ BadVar _ (Just (Rigid maybeName)) ->
718+ go $ singleRigidError maybeName
719719
720720 BadVar _ _ ->
721721 Nothing
@@ -728,18 +728,44 @@ badFieldElaboration =
728728 \ So the problem may actually be a weird interaction with previous fields."
729729
730730
731−singleRigidError :: String
732−singleRigidError =
733− "A type annotation is too generic. You can probably just switch to the\
734− \ type I inferred. These issues can be subtle though, so read more about it. "
735− ++ Help.hintLink "type-annotations"
731+weirdRigidError :: String
732+weirdRigidError =
733+ "You are having a problem with \"rigid\" type variables. That usually\
734+ \ means you have a type annotation that says it accepts anything, but\
735+ \ in fact, it accepts a much more specific type. More info at: "
736+ ++ Help.hintLink "type-annotations" ++
737+ ". This case is weird though, so please turn it into an <http://sscce.org>\
738+ \ and report it to <https://github.com/elm-lang/error-message-catalog>."
736739
737740
738−doubleRigidError :: String
739−doubleRigidError =
740− "A type annotation is clashing with itself or with a sub-annotation.\
741− \ This can be particularly tricky, so read more about it. "
742− ++ Help.hintLink "type-annotations"
741+singleRigidError :: Maybe String -> String
742+singleRigidError maybeName =
743+ case maybeName of
744+ Just name ->
745+ "Your type annotation uses type variable `" ++ name ++
746+ "` which means any type of value can flow through. Your code is saying\
747+ \ it CANNOT be anything though! Maybe change your type annotation to\
748+ \ be more specific? Maybe the code has a problem? More at: "
749+ ++ Help.hintLink "type-annotations"
750+
751+ Nothing ->
752+ weirdRigidError
753+
754+
755+doubleRigidError :: Maybe String -> Maybe String -> String
756+doubleRigidError maybeLeftName maybeRightName =
757+ case (maybeLeftName, maybeRightName) of
758+ (Just leftName, Just rightName) ->
759+ "Your type annotation uses `" ++ leftName ++ "` and `" ++ rightName ++
760+ "` as separate type variables. Each one can be any type of value,\
761+ \ but because they have separate names, there is no guarantee that they\
762+ \ are equal to each other. Your code seems to be saying they ARE the\
763+ \ same though! Maybe they should be the same in your type annotation?\
764+ \ Maybe your code uses them in a weird way? More at: "
765+ ++ Help.hintLink "type-annotations"
766+
767+ _ ->
768+ weirdRigidError
743769
744770
745771hintDoc :: Doc