on master help sign in
Merge pull request #1137 from elm-lang/dev

Provide nicer message when trying to use a non-function as a function

commit8bbb58000be8c3c8e6432caf89433c5323659950 authorEvan Czaplicki <info@elm-lang.org> dateWed 28 Oct 2015, 16:31 (11 years ago) parent086c50d018d8a0
1 file changed+20−2
src/Reporting/Error/Type.hs+20−2
src/Reporting/Error/Type.hs+20−2
@@ -302,16 +302,34 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
302302 )
303303 )
304304
305+ FunctionArity maybeName 0 actual region ->
306+ let
307+ arg =
308+ if actual == 1 then "an argument" else show actual ++ " arguments"
309+
310+ preHint =
311+ case maybeName of
312+ Nothing ->
313+ "You are giving " ++ arg ++ " to something that is not a function!"
314+
315+ Just name ->
316+ prettyName name ++ " is not a function, but you are giving it " ++ arg ++ "!"
317+ in
318+ report
319+ (Just region)
320+ preHint
321+ (text "Maybe you forgot some parentheses? Or a comma?")
322+
305323 FunctionArity maybeName expected actual region ->
306324 let
307− s = if expected <= 1 then "" else "s"
325+ s = if expected == 1 then "" else "s"
308326 in
309327 report
310328 (Just region)
311329 ( Help.capitalize (funcName maybeName) ++ " is expecting " ++ show expected
312330 ++ " argument" ++ s ++ ", but was given " ++ show actual ++ "."
313331 )
314− (text "Maybe you forgot some parentheses somewhere?")
332+ (text "Maybe you forgot some parentheses? Or a comma?")
315333
316334 BadTypeAnnotation name ->
317335 report