on master help sign in
Fix unification of String/appendable and Char/comparable
097ac1eEvan Czaplicki
src/Reporting/Error/Type.hs+43−15
@@ -471,18 +471,18 @@ problemToHint problem =
471
471
472 T.BadFlexSuper super _ tipe ->
472 T.BadFlexSuper super _ tipe ->
473 case tipe of
473 case tipe of
474− T.Lambda _ _ _ -> badFlexSuper super
474+ T.Lambda _ _ _ -> badFlexSuper super tipe
475 T.Infinite -> []
475 T.Infinite -> []
476 T.Error -> []
476 T.Error -> []
477 T.FlexVar _ -> []
477 T.FlexVar _ -> []
478 T.FlexSuper s _ -> badFlexFlexSuper super s
478 T.FlexSuper s _ -> badFlexFlexSuper super s
479 T.RigidVar y -> badRigidVar y (toASuperThing super)
479 T.RigidVar y -> badRigidVar y (toASuperThing super)
480 T.RigidSuper s _ -> badRigidSuper s (toASuperThing super)
480 T.RigidSuper s _ -> badRigidSuper s (toASuperThing super)
481− T.Type _ _ _ -> badFlexSuper super
481+ T.Type h n _ -> badFlexSuper super tipe
482− T.Record _ _ -> badFlexSuper super
482+ T.Record _ _ -> badFlexSuper super tipe
483− T.Unit -> badFlexSuper super
483+ T.Unit -> badFlexSuper super tipe
484− T.Tuple _ _ _ -> badFlexSuper super
484+ T.Tuple _ _ _ -> badFlexSuper super tipe
485− T.Alias _ _ _ _ -> badFlexSuper super
485+ T.Alias _ _ _ _ -> badFlexSuper super tipe
486
486
487 T.BadRigidVar x tipe ->
487 T.BadRigidVar x tipe ->
488 case tipe of
488 case tipe of
@@ -554,16 +554,45 @@ toASuperThing super =
554-- BAD SUPER HINTS
554-- BAD SUPER HINTS
555
555
556
556
557−badFlexSuper :: T.Super -> [H.Doc]
557+badFlexSuper :: T.Super -> T.Type -> [H.Doc]
558−badFlexSuper super =
558+badFlexSuper super tipe =
559 case super of
559 case super of
560+ T.Comparable ->
560− T.Comparable -> [ H.toSimpleHint "Only ints, floats, chars, strings, lists, and tuples are comparable." ]
561+ [ H.toSimpleHint "Only ints, floats, chars, strings, lists, and tuples are comparable."
561− T.Appendable -> [ H.toSimpleHint "Only strings and lists are appendable." ]
562+ ]
563+
564+ T.Appendable ->
565+ case tipe of
566+ T.Type home name _ | T.isInt home name ->
567+ [ H.toFancyHint ["Try","using",H.green"String.fromInt","to","convert","it","to","a","string?"]
568+ ]
569+
570+ T.Type home name _ | T.isFloat home name ->
571+ [ H.toFancyHint ["Try","using",H.green"String.fromFloat","to","convert","it","to","a","string?"]
572+ ]
573+
574+ T.FlexSuper T.Number _ ->
575+ [ H.toFancyHint ["Try","using",H.green"String.fromInt","to","convert","it","to","a","string?"]
576+ ]
577+
578+ _ ->
579+ [ H.toFancyHint ["Only","strings","and","lists","are","appendable.","Put","it","in",H.green "[]","to","make","it","a","list?"]
580+ ]
581+
582+ T.CompAppend ->
562− T.CompAppend -> [ H.toSimpleHint "Only strings and lists are both comparable and appendable." ]
583+ [ H.toSimpleHint "Only strings and lists are both comparable and appendable."
563− T.Number ->
564− [ H.toFancyHint ["Only",H.green "Int","and",H.green "Float","values","work","as","numbers."]
565 ]
584 ]
566
585
586+ T.Number ->
587+ case tipe of
588+ T.Type home name _ | T.isString home name ->
589+ [ H.toFancyHint ["Try","using",H.green"String.toInt","to","convert","it","to","a","number?"]
590+ ]
591+
592+ _ ->
593+ [ H.toFancyHint ["Only",H.green "Int","and",H.green "Float","values","work","as","numbers."]
594+ ]
595+
567
596
568badRigidSuper :: T.Super -> String -> [H.Doc]
597badRigidSuper :: T.Super -> String -> [H.Doc]
569badRigidSuper super aThing =
598badRigidSuper super aThing =
@@ -1282,8 +1311,7 @@ badAppendLeft localizer category tipe expected =
1282 ANumber thing stringFromThing ->
1311 ANumber thing stringFromThing ->
1283 (
1312 (
1284 H.fillSep
1313 H.fillSep
1285− ["The","(++)","operator","can","append"
1314+ ["The","(++)","operator","can","append","List","and","String"
1286− ,H.dullyellow "List","and",H.dullyellow "String"
1287 ,"values,","but","not",H.dullyellow thing,"values","like","this:"
1315 ,"values,","but","not",H.dullyellow thing,"values","like","this:"
1288 ]
1316 ]
1289 ,
1317 ,
src/Type/Error.hs+6
@@ -12,6 +12,7 @@ module Type.Error
12 , isInt
12 , isInt
13 , isFloat
13 , isFloat
14 , isString
14 , isString
15+ , isChar
15 , isList
16 , isList
16 )
17 )
17 where
18 where
@@ -313,6 +314,11 @@ isString home name =
313 home == ModuleName.string && name == N.string
314 home == ModuleName.string && name == N.string
314
315
315
316
317+isChar :: ModuleName.Canonical -> N.Name -> Bool
318+isChar home name =
319+ home == ModuleName.char && name == N.char
320+
321+
316isMaybe :: ModuleName.Canonical -> N.Name -> Bool
322isMaybe :: ModuleName.Canonical -> N.Name -> Bool
317isMaybe home name =
323isMaybe home name =
318 home == ModuleName.maybe && name == N.maybe
324 home == ModuleName.maybe && name == N.maybe
src/Type/Unify.hs+13−10
@@ -360,24 +360,27 @@ combineRigidSupers rigid flex =
360
360
361atomMatchesSuper :: SuperType -> ModuleName.Canonical -> N.Name -> Bool
361atomMatchesSuper :: SuperType -> ModuleName.Canonical -> N.Name -> Bool
362atomMatchesSuper super home name =
362atomMatchesSuper super home name =
363− home == ModuleName.basics
364− &&
365 case super of
363 case super of
366 Number ->
364 Number ->
367− name == N.int
365+ isNumber home name
368− || name == N.float
369
366
370 Comparable ->
367 Comparable ->
371− name == N.int
368+ isNumber home name
372− || name == N.float
369+ || Error.isString home name
373− || name == N.string
370+ || Error.isChar home name
374− || name == N.char
375
371
376 Appendable ->
372 Appendable ->
377− name == N.string
373+ Error.isString home name
378
374
379 CompAppend ->
375 CompAppend ->
380− name == N.string
376+ Error.isString home name
377+
378+
379+isNumber :: ModuleName.Canonical -> N.Name -> Bool
380+isNumber home name =
381+ home == ModuleName.basics
382+ &&
383+ (name == N.int || name == N.float)
381
384
382
385
383unifyFlexSuperStructure :: Context -> SuperType -> FlatType -> Unify ()
386unifyFlexSuperStructure :: Context -> SuperType -> FlatType -> Unify ()