on master help sign in
Fix presentation bug with unbound type variable errors
410ab22Evan Czaplicki
src/Reporting/Error/Syntax.hs+11−14
@@ -117,20 +117,17 @@ toReport err =
117
117
118unboundTypeVars :: String -> String -> [String] -> String -> Report.Report
118unboundTypeVars :: String -> String -> [String] -> String -> Report.Report
119unboundTypeVars typeName tvar tvars revisedDeclaration =
119unboundTypeVars typeName tvar tvars revisedDeclaration =
120− let
121− s = if null tvars then "" else "s"
122− in
123− Report.simple
120+ Report.simple
124− ("Type '" ++ typeName ++ "' uses unbound type variable" ++ s ++ ": "
121+ ( "Not all type variables in '" ++ typeName ++ "' are listed, making sneaky\n"
125− ++ List.intercalate ", " (tvar:tvars)
122+ ++ "type errors possible. Unbound type variables include: "
126− )
123+ ++ List.intercalate ", " (tvar:tvars)
127− ("All type variables must be listed to avoid sneaky type errors.\n"
124+ )
128− ++ "Imagine one '" ++ typeName ++ "' where '" ++ tvar ++ "' is an Int and\n"
125+ ( "Here's the problem. Imagine one '" ++ typeName ++ "' where '" ++ tvar ++ "' is an Int and\n"
129− ++ "another where it is a Bool. They both look like a '" ++ typeName ++ "'\n"
126+ ++ "another where it is a Bool. They both look like a '" ++ typeName ++ "' to the type\n"
130− ++ "to the type checker, but they are actually different types!\n\n"
127+ ++ "checker, but they are actually different types!\n\n"
131− ++ "Maybe you want a definition like this?\n"
128+ ++ "Maybe you want a definition like this?\n"
132− ++ concatMap ("\n "++) (lines revisedDeclaration)
129+ ++ concatMap ("\n "++) (lines revisedDeclaration)
133− )
130+ )
134
131
135
132
136parseErrorHint :: Parsec.Message -> String
133parseErrorHint :: Parsec.Message -> String
src/Validate.hs+12−6
@@ -352,18 +352,24 @@ checkDecl (A.A region decl) =
352 [] ->
352 [] ->
353 return ()
353 return ()
354
354
355− v:vs ->
355+ unbound ->
356+ let
357+ (v:vs) = Set.toList (Set.fromList unbound)
358+ in
356− Result.throw region
359+ Result.throw region
357− (Error.UnboundTypeVarsInUnion name boundVars v vs ctors)
360+ (Error.UnboundTypeVarsInUnion name boundVars v vs ctors)
358
361
359 D.TypeAlias name boundVars tipe ->
362 D.TypeAlias name boundVars tipe ->
360 case findUnbound boundVars (freeVars tipe) of
363 case findUnbound boundVars (freeVars tipe) of
361 [] ->
364 [] ->
362 return ()
365 return ()
363
366
364− v:vs ->
367+ unbound ->
368+ let
369+ (v:vs) = Set.toList (Set.fromList unbound)
370+ in
365− Result.throw region
371+ Result.throw region
366− (Error.UnboundTypeVarsInAlias name boundVars v vs tipe)
372+ (Error.UnboundTypeVarsInAlias name boundVars v vs tipe)
367
373
368 D.Port _ ->
374 D.Port _ ->
369 return ()
375 return ()