on master help sign in
Fix presentation bug with unbound type variable errors
commit410ab2275177f4ad39e891cd48464c83dfc98903 authorEvan Czaplicki <info@elm-lang.org> dateFri 8 May 2015, 18:36 (11 years ago) parentb76ad63
2 files changed+23−20
src/Reporting/Error/Syntax.hs+11−14 src/Validate.hs+12−6
src/Reporting/Error/Syntax.hs+11−14
@@ -117,20 +117,17 @@ toReport err =
117117
118118unboundTypeVars :: String -> String -> [String] -> String -> Report.Report
119119unboundTypeVars typeName tvar tvars revisedDeclaration =
120− let
121− s = if null tvars then "" else "s"
122− in
123− Report.simple
124− ("Type '" ++ typeName ++ "' uses unbound type variable" ++ s ++ ": "
125− ++ List.intercalate ", " (tvar:tvars)
126− )
127− ("All type variables must be listed to avoid sneaky type errors.\n"
128− ++ "Imagine one '" ++ typeName ++ "' where '" ++ tvar ++ "' is an Int and\n"
129− ++ "another where it is a Bool. They both look like a '" ++ typeName ++ "'\n"
130− ++ "to the type checker, but they are actually different types!\n\n"
131− ++ "Maybe you want a definition like this?\n"
132− ++ concatMap ("\n "++) (lines revisedDeclaration)
133− )
120+ Report.simple
121+ ( "Not all type variables in '" ++ typeName ++ "' are listed, making sneaky\n"
122+ ++ "type errors possible. Unbound type variables include: "
123+ ++ List.intercalate ", " (tvar:tvars)
124+ )
125+ ( "Here's the problem. Imagine one '" ++ typeName ++ "' where '" ++ tvar ++ "' is an Int and\n"
126+ ++ "another where it is a Bool. They both look like a '" ++ typeName ++ "' to the type\n"
127+ ++ "checker, but they are actually different types!\n\n"
128+ ++ "Maybe you want a definition like this?\n"
129+ ++ concatMap ("\n "++) (lines revisedDeclaration)
130+ )
134131
135132
136133parseErrorHint :: Parsec.Message -> String
src/Validate.hs+12−6
@@ -352,18 +352,24 @@ checkDecl (A.A region decl) =
352352 [] ->
353353 return ()
354354
355− v:vs ->
356− Result.throw region
357− (Error.UnboundTypeVarsInUnion name boundVars v vs ctors)
355+ unbound ->
356+ let
357+ (v:vs) = Set.toList (Set.fromList unbound)
358+ in
359+ Result.throw region
360+ (Error.UnboundTypeVarsInUnion name boundVars v vs ctors)
358361
359362 D.TypeAlias name boundVars tipe ->
360363 case findUnbound boundVars (freeVars tipe) of
361364 [] ->
362365 return ()
363366
364− v:vs ->
365− Result.throw region
366− (Error.UnboundTypeVarsInAlias name boundVars v vs tipe)
367+ unbound ->
368+ let
369+ (v:vs) = Set.toList (Set.fromList unbound)
370+ in
371+ Result.throw region
372+ (Error.UnboundTypeVarsInAlias name boundVars v vs tipe)
367373
368374 D.Port _ ->
369375 return ()