# strange/misleading function signature in error messages when using named parameters

**URL:** <https://discourse.julialang.org/t/strange-misleading-function-signature-in-error-messages-when-using-named-parameters/8949>\
**Category:** General Usage\
**Created:** [February 9, 2018, 12:52pm UTC](https://discourse.julialang.org/t/strange-misleading-function-signature-in-error-messages-when-using-named-parameters/8949 "2018-02-09T12:52:44Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mkaut](https://avatars.discourse-cdn.com/v4/letter/m/2bfe46/32.png) [@mkaut](https://discourse.julialang.org/u/mkaut)\
**Post date:** [February 9, 2018, 12:52pm UTC](https://discourse.julialang.org/t/strange-misleading-function-signature-in-error-messages-when-using-named-parameters/8949/1 "2018-02-09T12:52:44Z")

</div>

I wrote a function with the following signature: `function setOptimStatus(patientID::Int, status::String; rcProject::PyObject=0, repeatInst::Int=0)`.

When called with two parameters, I get the following error message:

```
ERROR: MethodError: no method matching #setOptimStatus#37(::Int64, ::Int64, ::#setOptimStatus, ::Int64, ::String)                      
Closest candidates are:                                                                                                                
  #setOptimStatus#37(::PyCall.PyObject, ::Int64, ::Any, ::Int64, ::String) at /path/source.jl:xxx      

```

I find the function signature in the error message misleading, since it states 5 parameters, while the function only has 4. Moreover, the parameters are in strange order: (3, 4, X, 1, 2), where X is the additional/dummy parameter.

Is this meant to be so, or is it a bug? (And if the latter, should I report it?)

By the way, to remove the error, all I needed to do was to change the third parameter to `rcProject::PyObject=PyObject(0)`, because otherwise it converts the value to `Int` … which I also find strange: since the parameter is specified to be of type `PyObject` – is this a bug?  
Instead, I would expect one of the following to happen:

- 0 gets converted to `PyObject(0)` automatically and everything works
- I get an error that 0 cannot be converted to `PyObject(0)` … ideally during compilation, instead of runtime, but that is probably just my `C++`-brain talking…

---

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [February 9, 2018, 1:02pm UTC](https://discourse.julialang.org/t/strange-misleading-function-signature-in-error-messages-when-using-named-parameters/8949/2 "2018-02-09T13:02:09Z")

</div>

Your expectations are not yet entirely calibrated for the way Julia does stuff. You have specified the type of the second function argumet as PyObject. That is a specific kind of thing. Generally, the quiet conversion of a zero to a PyObject, while unsurprising to the Python programmer, is not desireable (it opens up the possibility of badness that goes unnoticed).

---

<div class="post-metadata">

**Author:** ![Ralph\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ralph_smith/32/10344_2.png) [@Ralph\_Smith](https://discourse.julialang.org/u/Ralph_Smith)\
**Post date:** [February 9, 2018, 1:38pm UTC](https://discourse.julialang.org/t/strange-misleading-function-signature-in-error-messages-when-using-named-parameters/8949/3 "2018-02-09T13:38:16Z")

</div>

> [@mkaut](#):
>
> I find the function signature in the error message misleading, since it states 5 parameters, while the function only has 4.

`#setOptimStatus#37` is not the function you wrote, it is an “anonymous” function created by the compiler to deal with the keyword arguments.

---

<div class="post-metadata">

**Author:** ![mkaut](https://avatars.discourse-cdn.com/v4/letter/m/2bfe46/32.png) [@mkaut](https://discourse.julialang.org/u/mkaut)\
**Post date:** [February 9, 2018, 2:20pm UTC](https://discourse.julialang.org/t/strange-misleading-function-signature-in-error-messages-when-using-named-parameters/8949/4 "2018-02-09T14:20:32Z")

</div>

I understand that argument - but then it should complain that the default argument has wrong type (and, again, this should/could be caught by the compiler), instead of ignoring the specified type and converting it to Int.

---

<div class="post-metadata">

**Author:** ![mkaut](https://avatars.discourse-cdn.com/v4/letter/m/2bfe46/32.png) [@mkaut](https://discourse.julialang.org/u/mkaut)\
**Post date:** [February 9, 2018, 2:20pm UTC](https://discourse.julialang.org/t/strange-misleading-function-signature-in-error-messages-when-using-named-parameters/8949/5 "2018-02-09T14:20:39Z")

</div>

But why should I be interested in error message from a function that compiler created? Is there no way for the compiler to formulate the error message in terms of the function I actually wrote?

---

<div class="post-metadata">

**Author:** ![Ralph\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ralph_smith/32/10344_2.png) [@Ralph\_Smith](https://discourse.julialang.org/u/Ralph_Smith)\
**Post date:** [February 9, 2018, 2:29pm UTC](https://discourse.julialang.org/t/strange-misleading-function-signature-in-error-messages-when-using-named-parameters/8949/6 "2018-02-09T14:29:26Z")

</div>

Yes, it’s confusing. There are a couple of issues open for it, e.g. [13599](https://github.com/JuliaLang/julia/issues/13599). Presumably it is nontrivial to fix.

---

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [February 9, 2018, 2:33pm UTC](https://discourse.julialang.org/t/strange-misleading-function-signature-in-error-messages-when-using-named-parameters/8949/7 "2018-02-09T14:33:15Z")

</div>

With Julia, it is useful first to consider solving software tasks in terms of the clarity of their expressed types and the patterns of dispatch which most adroitly serve.

You should not be specifying that an argument must be of a specific type and simultaneously giving it a default value of some other type. Our frame.

---

<div class="post-metadata">

**Author:** ![mkaut](https://avatars.discourse-cdn.com/v4/letter/m/2bfe46/32.png) [@mkaut](https://discourse.julialang.org/u/mkaut)\
**Post date:** [February 9, 2018, 2:48pm UTC](https://discourse.julialang.org/t/strange-misleading-function-signature-in-error-messages-when-using-named-parameters/8949/8 "2018-02-09T14:48:30Z")

</div>

Thanks for the link. Another relevant issue is [16490](https://github.com/JuliaLang/julia/issues/16490).  
At least I know that this is considered an issue and, hopefully, worked on.

---

<div class="post-metadata">

**Author:** ![mkaut](https://avatars.discourse-cdn.com/v4/letter/m/2bfe46/32.png) [@mkaut](https://discourse.julialang.org/u/mkaut)\
**Post date:** [February 9, 2018, 2:51pm UTC](https://discourse.julialang.org/t/strange-misleading-function-signature-in-error-messages-when-using-named-parameters/8949/9 "2018-02-09T14:51:35Z")

</div>

Again, I agree that I “should not be specifying that an argument must be of a specific type and simultaneously giving it a default value of some other type” - all I am asking for is that this explanation as an error message, instead of a complaint about a non-existing function.

---

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [February 9, 2018, 4:01pm UTC](https://discourse.julialang.org/t/strange-misleading-function-signature-in-error-messages-when-using-named-parameters/8949/10 "2018-02-09T16:01:06Z")

</div>

That error message does not reflect an underlying design decision (all I know).
