# Unexpected response to syntax error in function definition

**URL:** <https://discourse.julialang.org/t/unexpected-response-to-syntax-error-in-function-definition/39548>\
**Category:** General Usage\
**Tags:** bug\
**Created:** [May 15, 2020, 6:30pm UTC](https://discourse.julialang.org/t/unexpected-response-to-syntax-error-in-function-definition/39548 "2020-05-15T18:30:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![portig](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/portig/32/5753_2.png) [@portig](https://discourse.julialang.org/u/portig)\
**Post date:** [May 15, 2020, 6:30pm UTC](https://discourse.julialang.org/t/unexpected-response-to-syntax-error-in-function-definition/39548/1 "2020-05-15T18:30:09Z")

</div>

Here is a REPL session demonstrating the issue. The function definition contains an error, but Julia’s response is puzzling and not helpful.

```julia
-> function ff(a; b::Int64=0.5)
       println(a)
       println(b)
       end
ff (generic function with 1 method)

-> ff("Hello", b=1)
Hello
1

-> ff("Hello")
ERROR: MethodError: no method matching #ff#5(::Float64, ::typeof(ff), ::String)
Closest candidates are:
  #ff#5(::Int64, ::typeof(ff), ::Any) at REPL[1]:2
Stacktrace:
 [1] ff(::String) at ./REPL[1]:2
 [2] top-level scope at REPL[3]:1
 [3] eval(::Module, ::Any) at ./boot.jl:331
 [4] eval_user_input(::Any, ::REPL.REPLBackend) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:86
 [5] run_backend(::REPL.REPLBackend) at /Users/Harald/.julia/packages/Revise/AMRie/src/Revise.jl:1023
 [6] top-level scope at none:0

-> ff("Hello", b=10)
Hello
10

-> ff("Hello", b=10.0)
ERROR: TypeError: in keyword argument b, expected Int64, got Float64
Stacktrace:
 [1] top-level scope at REPL[5]:1
 [2] eval(::Module, ::Any) at ./boot.jl:331
 [3] eval_user_input(::Any, ::REPL.REPLBackend) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:86
 [4] run_backend(::REPL.REPLBackend) at /Users/Harald/.julia/packages/Revise/AMRie/src/Revise.jl:1023
 [5] top-level scope at none:0

```

The problem in the function header, that 0.5 is not an Int64, should have been noted as an error when first defining the function. Instead a strange message is issued when the function is being called and the improperly defined argument is not used in the call.

This problem happened to me in a much more complicated context and caused me to spend an inordinate amount of time to understand it. I even removed Julia from my system and reinstalled it thinking that it had gotten polluted.

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [May 15, 2020, 6:33pm UTC](https://discourse.julialang.org/t/unexpected-response-to-syntax-error-in-function-definition/39548/2 "2020-05-15T18:33:03Z")

</div>

See [Obscure error with incorrect keyword argument defaults · Issue #13599 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/13599)

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [May 15, 2020, 6:35pm UTC](https://discourse.julialang.org/t/unexpected-response-to-syntax-error-in-function-definition/39548/3 "2020-05-15T18:35:50Z")

</div>

Also [https://github.com/JuliaLang/julia/issues/7357](https://github.com/JuliaLang/julia/issues/7357) and [Types on kwargs can lead to confusing situations · Issue #16490 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/16490).

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [May 16, 2020, 6:55am UTC](https://discourse.julialang.org/t/unexpected-response-to-syntax-error-in-function-definition/39548/4 "2020-05-16T06:55:28Z")

</div>

> [@portig](#):
>
> that 0.5 is not an Int64, should have been noted as an error when first defining the function

I agree the error message could be more helpful (see the issues above), but I am not sure that the language should raise an error if you define something like

```julia
f(; a::Int = nothing) = 1

```

After all, it is a perfectly valid method and can be called with the right arguments.
