# Unexpected method error during function call

**URL:** <https://discourse.julialang.org/t/unexpected-method-error-during-function-call/27452>\
**Category:** New to Julia\
**Created:** [August 12, 2019, 12:21pm UTC](https://discourse.julialang.org/t/unexpected-method-error-during-function-call/27452 "2019-08-12T12:21:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rocflight83](https://avatars.discourse-cdn.com/v4/letter/r/3ec8ea/32.png) [@rocflight83](https://discourse.julialang.org/u/rocflight83)\
**Post date:** [August 12, 2019, 12:21pm UTC](https://discourse.julialang.org/t/unexpected-method-error-during-function-call/27452/1 "2019-08-12T12:21:05Z")

</div>

Why does the following code cause a method error on adding type nothing with an Int?

```julia
function flipname(nm)
    i = findfirst(isequal(','), nm) # returns type nothing if finds no occurrence
    i == nothing ? nm : nm[i+2:length(nm)] * " " * nm[1:i-1]
end

```

```julia
flipname("test")

```

Meanwhile, the following code behaves as expected:

```julia
n = nothing
n == nothing ? println("nothing") : n + 1

```

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [August 12, 2019, 12:32pm UTC](https://discourse.julialang.org/t/unexpected-method-error-during-function-call/27452/2 "2019-08-12T12:32:29Z")

</div>

How do you call the function to provoke the error?  
Because for me:

```julia
julia> flipname("a, b")
"b a"
julia> flipname("ab")
"ab"
julia> flipname("a,b")
" a"

```

it works somehow.

---

<div class="post-metadata">

**Author:** ![rocflight83](https://avatars.discourse-cdn.com/v4/letter/r/3ec8ea/32.png) [@rocflight83](https://discourse.julialang.org/u/rocflight83)\
**Post date:** [August 12, 2019, 1:01pm UTC](https://discourse.julialang.org/t/unexpected-method-error-during-function-call/27452/3 "2019-08-12T13:01:02Z")

</div>

weird, had been running in jupyter notebook and

```julia
flipname("ab")

```

returned the method error.

Restarted the kernel and back to expected output somehow

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [August 12, 2019, 1:13pm UTC](https://discourse.julialang.org/t/unexpected-method-error-during-function-call/27452/4 "2019-08-12T13:13:18Z")

</div>

There was probably another `flipname()` method which you had defined previously in that same Jupyter kernel session. For example, you might have had a `flipname(nm::AbstractString)` or `flipname(nm::String)`, so defining another more general method `flipname(nm)` would not _replace_ that old method but would happily live alongside it.

This sort of thing is much easier for us to help with if you can post the _full_ error output, including the stack trace, rather than just saying that the code causes an error.

---

<div class="post-metadata">

**Author:** ![rocflight83](https://avatars.discourse-cdn.com/v4/letter/r/3ec8ea/32.png) [@rocflight83](https://discourse.julialang.org/u/rocflight83)\
**Post date:** [August 12, 2019, 3:22pm UTC](https://discourse.julialang.org/t/unexpected-method-error-during-function-call/27452/5 "2019-08-12T15:22:05Z")

</div>

That’s exactly the issue, thx.

Will do on posting full error msgs in the future.
