on master help sign in
Have a proper hint for infinite type errors
commit6948b5df90bb75e33dc06d0e4a19cb88d71bedb5 authorEvan Czaplicki <info@elm-lang.org> dateTue 5 May 2015, 13:05 (11 years ago) parentf678e11
1 file changed+9−3
src/Reporting/Error/Type.hs+9−3
src/Reporting/Error/Type.hs+9−3
@@ -12,7 +12,7 @@ import qualified Reporting.Region as R
1212
1313data Error
1414 = Mismatch Mismatch
15− | InfiniteType
15+ | InfiniteType String T.Canonical
1616 | BadMain T.Canonical
1717
1818
@@ -53,8 +53,14 @@ toHint err =
5353 ++ "\n\nBut other evidence suggests:\n\n"
5454 ++ P.render (P.nest 4 (P.pretty False rightType))
5555
56− InfiniteType ->
57− error "TODO"
56+ InfiniteType var tipe ->
57+ "This expression is leading me to infer an infinite type. Maybe you are trying\n"
58+ ++ "to do some tricky recursion? Try breaking the expression into smaller pieces.\n"
59+ ++ "Give each piece a name and try to write down its type.\n\n"
60+ ++ "The evidence is suggesting that type '" ++ var ++ "' is equal to:\n\n"
61+ ++ P.render (P.nest 4 (P.pretty False tipe))
62+ ++ "\n\nNotice that type variable '" ++ var ++ "' appears there too, so if we\n"
63+ ++ "expanded this type, it would just keep getting bigger and bigger."
5864
5965 BadMain tipe ->
6066 "The 'main' value has an unsupported type:\n\n"