# Surprising StackOverflowError

**URL:** https://discourse.julialang.org/t/surprising-stackoverflowerror/43277
**Category:** General Usage
**Created:** [July 18, 2020, 7:28am UTC](https://discourse.julialang.org/t/surprising-stackoverflowerror/43277 "2020-07-18T07:28:32Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Bigorneau](https://avatars.discourse-cdn.com/v4/letter/b/4491bb/32.png) [@Bigorneau](https://discourse.julialang.org/u/Bigorneau)
#### Post date: [July 18, 2020, 7:28am UTC](https://discourse.julialang.org/t/surprising-stackoverflowerror/43277/1 "2020-07-18T07:28:32Z")

</div>

I encountered a surprising error today. The following two lines result in a StackOverflowError (with Julia 1.4.2):

```nohighlight
f(x::T, y::T, z::S) where {S,T<:Vector{S}} = "method 1"
f(x::T, z::S, y::T) where {S,T<:Vector{S}} = "method 2"

```

I am struggling understanding why this is not allowed. Does anyone have an explanation? 🙂

EDIT: I should mention that

```nohighlight
f(x::Vector{S}, y::Vector{S}, z::S) where {S} = "method 1"
f(x::Vector{S}, z::S, y::Vector{S}) where {S} = "method 2"

```

works properly.

---

<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: [July 18, 2020, 8:46am UTC](https://discourse.julialang.org/t/surprising-stackoverflowerror/43277/2 "2020-07-18T08:46:35Z")

</div>

Seems to be some kind of bug:

```julia
julia> f(x::T, y::T, z::S) where {S,T<:Vector{S}} = "method 1"
f (generic function with 1 method)

julia> f(x::T, z::S, y::T) where {S,T<:Vector{S}} = "method 2"
ERROR: StackOverflowError:
Stacktrace:
 [1] top-level scope at REPL[2]:1

julia> methods(f)
# 2 methods for generic function "f":
[1] f(x::T, y::T, z::S) where {S, T<:Array{S,1}} in Main at REPL[1]:1
[2] f(x::T, z::S, y::T) where {S, T<:Array{S,1}} in Main at REPL[2]:1

julia> f([1,2],1,[1,2])
"method 2"

julia> f([1,2],[1,2],1)
"method 1"

```

It happens in 1.5.0-rc1 too.

---

<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: [July 18, 2020, 12:40pm UTC](https://discourse.julialang.org/t/surprising-stackoverflowerror/43277/3 "2020-07-18T12:40:44Z")

</div>

I can confirm this on current master. Cf

[https://github.com/JuliaLang/julia/issues/31861](https://github.com/JuliaLang/julia/issues/31861)

which may be related (but it is worth asking there with the example above).
