on master help sign in
Figure out TODOs for FlexSuper vs RigidSuper hints
6f9825fEvan Czaplicki
src/Reporting/Error/Type.hs+43−35
@@ -476,9 +476,9 @@ problemToHint problem =
476 T.Infinite -> []
476 T.Infinite -> []
477 T.Error -> []
477 T.Error -> []
478 T.FlexVar _ -> []
478 T.FlexVar _ -> []
479− T.FlexSuper s _ -> badDoubleFlexSuper super s
479+ T.FlexSuper s _ -> badFlexFlexSuper super s
480 T.RigidVar y -> badRigidVar y (toASuperThing super)
480 T.RigidVar y -> badRigidVar y (toASuperThing super)
481− T.RigidSuper s _ -> error "TODO"
481+ T.RigidSuper s _ -> badRigidSuper s (toASuperThing super)
482 T.Type _ _ _ -> badFlexSuper super
482 T.Type _ _ _ -> badFlexSuper super
483 T.Record _ _ -> badFlexSuper super
483 T.Record _ _ -> badFlexSuper super
484 T.Unit -> badFlexSuper super
484 T.Unit -> badFlexSuper super
@@ -506,7 +506,7 @@ problemToHint problem =
506 T.Infinite -> []
506 T.Infinite -> []
507 T.Error -> []
507 T.Error -> []
508 T.FlexVar _ -> []
508 T.FlexVar _ -> []
509− T.FlexSuper s _ -> error "TODO"
509+ T.FlexSuper s _ -> badRigidSuper super (toASuperThing s)
510 T.RigidVar y -> badDoubleRigid x y
510 T.RigidVar y -> badDoubleRigid x y
511 T.RigidSuper _ y -> badDoubleRigid x y
511 T.RigidSuper _ y -> badDoubleRigid x y
512 T.Type _ n _ -> badRigidSuper super ("a `" ++ N.toString n ++ "` value")
512 T.Type _ n _ -> badRigidSuper super ("a `" ++ N.toString n ++ "` value")
@@ -516,15 +516,8 @@ problemToHint problem =
516 T.Alias _ n _ _ -> badRigidSuper super ("a `" ++ N.toString n ++ "` value")
516 T.Alias _ n _ _ -> badRigidSuper super ("a `" ++ N.toString n ++ "` value")
517
517
518
518
519−badFlexSuper :: T.Super -> [H.Doc]
519+
520−badFlexSuper super =
520+-- BAD RIGID HINTS
521− case super of
522− T.Comparable -> [ H.toSimpleHint "Only ints, floats, chars, strings, lists, and tuples are comparable." ]
523− T.Appendable -> [ H.toSimpleHint "Only strings and lists are appendable." ]
524− T.CompAppend -> [ H.toSimpleHint "Only strings and lists are both comparable and appendable." ]
525− T.Number ->
526− [ H.toFancyHint ["Only",H.green "Int","and",H.green "Float","values","work","as","numbers."]
527− ]
528
521
529
522
530badRigidVar :: N.Name -> String -> [H.Doc]
523badRigidVar :: N.Name -> String -> [H.Doc]
@@ -538,6 +531,17 @@ badRigidVar name aThing =
538 ]
531 ]
539
532
540
533
534+badDoubleRigid :: N.Name -> N.Name -> [H.Doc]
535+badDoubleRigid x y =
536+ [ H.toSimpleHint $
537+ "Your type annotation uses `" ++ N.toString x ++ "` and `" ++ N.toString y ++
538+ "` as separate type variables. Your code seems to be saying they are the\
539+ \ same though! Maybe they should be the same in your type annotation?\
540+ \ Maybe your code uses them in a weird way?"
541+ , H.reflowLink "Read" "type-annotations" "for more advice!"
542+ ]
543+
544+
541toASuperThing :: T.Super -> String
545toASuperThing :: T.Super -> String
542toASuperThing super =
546toASuperThing super =
543 case super of
547 case super of
@@ -547,20 +551,19 @@ toASuperThing super =
547 T.Appendable -> "an `appendable` value"
551 T.Appendable -> "an `appendable` value"
548
552
549
553
550−badDoubleFlexSuper :: T.Super -> T.Super -> [H.Doc]
554+
551−badDoubleFlexSuper s1 s2 =
555+-- BAD SUPER HINTS
552− let
556+
553− likeThis super =
557+
558+badFlexSuper :: T.Super -> [H.Doc]
559+badFlexSuper super =
554− case super of
560+ case super of
555− T.Number -> "a number"
556− T.Comparable -> "comparable"
561+ T.Comparable -> [ H.toSimpleHint "Only ints, floats, chars, strings, lists, and tuples are comparable." ]
557− T.CompAppend -> "a compappend"
562+ T.Appendable -> [ H.toSimpleHint "Only strings and lists are appendable." ]
558− T.Appendable -> "appendable"
563+ T.CompAppend -> [ H.toSimpleHint "Only strings and lists are both comparable and appendable." ]
559− in
564+ T.Number ->
560− [ H.toSimpleHint $
565+ [ H.toFancyHint ["Only",H.green "Int","and",H.green "Float","values","work","as","numbers."]
561− "There are no values in Elm that are both"
562− ++ likeThis s1 ++ " and " ++ likeThis s2 ++ "."
563− ]
566+ ]
564
567
565
568
566badRigidSuper :: T.Super -> String -> [H.Doc]
569badRigidSuper :: T.Super -> String -> [H.Doc]
@@ -582,15 +585,20 @@ badRigidSuper super aThing =
582 ]
585 ]
583
586
584
587
585−badDoubleRigid :: N.Name -> N.Name -> [H.Doc]
588+badFlexFlexSuper :: T.Super -> T.Super -> [H.Doc]
586−badDoubleRigid x y =
589+badFlexFlexSuper s1 s2 =
590+ let
591+ likeThis super =
592+ case super of
593+ T.Number -> "a number"
594+ T.Comparable -> "comparable"
595+ T.CompAppend -> "a compappend"
596+ T.Appendable -> "appendable"
597+ in
587− [ H.toSimpleHint $
598+ [ H.toSimpleHint $
588− "Your type annotation uses `" ++ N.toString x ++ "` and `" ++ N.toString y ++
599+ "There are no values in Elm that are both"
589− "` as separate type variables. Your code seems to be saying they are the\
600+ ++ likeThis s1 ++ " and " ++ likeThis s2 ++ "."
590− \ same though! Maybe they should be the same in your type annotation?\
591− \ Maybe your code uses them in a weird way?"
592− , H.reflowLink "Read" "type-annotations" "for more advice!"
593− ]
601+ ]
594
602
595
603
596
604