on master help sign in
Fix error message when you have a `number` but need a `String`
4ed70ccEvan Czaplicki
compiler/src/Reporting/Error/Type.hs+20−28
@@ -438,20 +438,20 @@ problemToHint problem =
438 T.MissingArgs _ -> []
438 T.MissingArgs _ -> []
439 T.ReturnMismatch -> []
439 T.ReturnMismatch -> []
440
440
441− T.BadFlexSuper super _ tipe ->
441+ T.BadFlexSuper direction super _ tipe ->
442 case tipe of
442 case tipe of
443− T.Lambda _ _ _ -> badFlexSuper super tipe
443+ T.Lambda _ _ _ -> badFlexSuper direction super tipe
444 T.Infinite -> []
444 T.Infinite -> []
445 T.Error -> []
445 T.Error -> []
446 T.FlexVar _ -> []
446 T.FlexVar _ -> []
447 T.FlexSuper s _ -> badFlexFlexSuper super s
447 T.FlexSuper s _ -> badFlexFlexSuper super s
448 T.RigidVar y -> badRigidVar y (toASuperThing super)
448 T.RigidVar y -> badRigidVar y (toASuperThing super)
449 T.RigidSuper s _ -> badRigidSuper s (toASuperThing super)
449 T.RigidSuper s _ -> badRigidSuper s (toASuperThing super)
450− T.Type _ _ _ -> badFlexSuper super tipe
450+ T.Type _ _ _ -> badFlexSuper direction super tipe
451− T.Record _ _ -> badFlexSuper super tipe
451+ T.Record _ _ -> badFlexSuper direction super tipe
452− T.Unit -> badFlexSuper super tipe
452+ T.Unit -> badFlexSuper direction super tipe
453− T.Tuple _ _ _ -> badFlexSuper super tipe
453+ T.Tuple _ _ _ -> badFlexSuper direction super tipe
454− T.Alias _ _ _ _ -> badFlexSuper super tipe
454+ T.Alias _ _ _ _ -> badFlexSuper direction super tipe
455
455
456 T.BadRigidVar x tipe ->
456 T.BadRigidVar x tipe ->
457 case tipe of
457 case tipe of
@@ -535,7 +535,7 @@ badDoubleRigid x y =
535 [ D.toSimpleHint $
535 [ D.toSimpleHint $
536 "Your type annotation uses `" ++ N.toString x ++ "` and `" ++ N.toString y ++
536 "Your type annotation uses `" ++ N.toString x ++ "` and `" ++ N.toString y ++
537 "` as separate type variables. Your code seems to be saying they are the\
537 "` as separate type variables. Your code seems to be saying they are the\
538− \ same though! Maybe they should be the same in your type annotation?\
538+ \ same though. Maybe they should be the same in your type annotation?\
539 \ Maybe your code uses them in a weird way?"
539 \ Maybe your code uses them in a weird way?"
540 , D.reflowLink "Read" "type-annotations" "for more advice!"
540 , D.reflowLink "Read" "type-annotations" "for more advice!"
541 ]
541 ]
@@ -554,30 +554,16 @@ toASuperThing super =
554-- BAD SUPER HINTS
554-- BAD SUPER HINTS
555
555
556
556
557−badFlexSuper :: T.Super -> T.Type -> [D.Doc]
557+badFlexSuper :: T.Direction -> T.Super -> T.Type -> [D.Doc]
558−badFlexSuper super tipe =
558+badFlexSuper direction super tipe =
559 case super of
559 case super of
560 T.Comparable ->
560 T.Comparable ->
561 [ D.toSimpleHint "Only ints, floats, chars, strings, lists, and tuples are comparable."
561 [ D.toSimpleHint "Only ints, floats, chars, strings, lists, and tuples are comparable."
562 ]
562 ]
563
563
564 T.Appendable ->
564 T.Appendable ->
565− case tipe of
566− T.Type home name _ | T.isInt home name ->
567− [ D.toFancyHint ["Try","using",D.green"String.fromInt","to","convert","it","to","a","string?"]
568− ]
569−
570− T.Type home name _ | T.isFloat home name ->
571− [ D.toFancyHint ["Try","using",D.green"String.fromFloat","to","convert","it","to","a","string?"]
572− ]
573−
574− T.FlexSuper T.Number _ ->
575− [ D.toFancyHint ["Try","using",D.green"String.fromInt","to","convert","it","to","a","string?"]
576− ]
577−
578− _ ->
579− [ D.toFancyHint ["Only","strings","and","lists","are","appendable.","Put","it","in",D.green "[]","to","make","it","a","list?"]
565+ [ D.toSimpleHint "Only strings and lists are appendable."
580− ]
566+ ]
581
567
582 T.CompAppend ->
568 T.CompAppend ->
583 [ D.toSimpleHint "Only strings and lists are both comparable and appendable."
569 [ D.toSimpleHint "Only strings and lists are both comparable and appendable."
@@ -586,8 +572,14 @@ badFlexSuper super tipe =
586 T.Number ->
572 T.Number ->
587 case tipe of
573 case tipe of
588 T.Type home name _ | T.isString home name ->
574 T.Type home name _ | T.isString home name ->
575+ case direction of
576+ T.Have ->
577+ [ D.toFancyHint ["Try","using",D.green "String.fromInt","to","convert","it","to","a","string?"]
578+ ]
579+
580+ T.Need ->
589− [ D.toFancyHint ["Try","using",D.green"String.toInt","to","convert","it","to","a","number?"]
581+ [ D.toFancyHint ["Try","using",D.green "String.toInt","to","convert","it","to","an","integer?"]
590− ]
582+ ]
591
583
592 _ ->
584 _ ->
593 [ D.toFancyHint ["Only",D.green "Int","and",D.green "Float","values","work","as","numbers."]
585 [ D.toFancyHint ["Only",D.green "Int","and",D.green "Float","values","work","as","numbers."]
compiler/src/Type/Error.hs+7−3
@@ -7,6 +7,7 @@ module Type.Error
7 , iteratedDealias
7 , iteratedDealias
8 , toDoc
8 , toDoc
9 , Problem(..)
9 , Problem(..)
10+ , Direction(..)
10 , toComparison
11 , toComparison
11 , isInt
12 , isInt
12 , isFloat
13 , isFloat
@@ -177,13 +178,16 @@ data Problem
177 | AnythingToList
178 | AnythingToList
178 | MissingArgs Int
179 | MissingArgs Int
179 | ReturnMismatch
180 | ReturnMismatch
180− | BadFlexSuper Super N.Name Type
181+ | BadFlexSuper Direction Super N.Name Type
181 | BadRigidVar N.Name Type
182 | BadRigidVar N.Name Type
182 | BadRigidSuper Super N.Name Type
183 | BadRigidSuper Super N.Name Type
183 | FieldTypo N.Name [N.Name]
184 | FieldTypo N.Name [N.Name]
184 | FieldsMissing [N.Name]
185 | FieldsMissing [N.Name]
185
186
186
187
188+data Direction = Have | Need
189+
190+
187instance Functor Diff where
191instance Functor Diff where
188 fmap func (Diff a b status) =
192 fmap func (Diff a b status) =
189 Diff (func a) (func b) status
193 Diff (func a) (func b) status
@@ -342,10 +346,10 @@ toDiff localizer ctx tipe1 tipe2 =
342 different doc1 doc2 $
346 different doc1 doc2 $
343 case pair of
347 case pair of
344 (RigidVar x, other) -> Bag.one $ BadRigidVar x other
348 (RigidVar x, other) -> Bag.one $ BadRigidVar x other
345− (FlexSuper s x, other) -> Bag.one $ BadFlexSuper s x other
349+ (FlexSuper s x, other) -> Bag.one $ BadFlexSuper Have s x other
346 (RigidSuper s x, other) -> Bag.one $ BadRigidSuper s x other
350 (RigidSuper s x, other) -> Bag.one $ BadRigidSuper s x other
347 (other, RigidVar x) -> Bag.one $ BadRigidVar x other
351 (other, RigidVar x) -> Bag.one $ BadRigidVar x other
348− (other, FlexSuper s x) -> Bag.one $ BadFlexSuper s x other
352+ (other, FlexSuper s x) -> Bag.one $ BadFlexSuper Need s x other
349 (other, RigidSuper s x) -> Bag.one $ BadRigidSuper s x other
353 (other, RigidSuper s x) -> Bag.one $ BadRigidSuper s x other
350
354
351 (Type home1 name1 [], Type home2 name2 [])
355 (Type home1 name1 [], Type home2 name2 [])