Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stackoverflow from recursive call in find_intersections #200

Open
ericphanson opened this issue Sep 12, 2022 · 0 comments · May be fixed by #201
Open

stackoverflow from recursive call in find_intersections #200

ericphanson opened this issue Sep 12, 2022 · 0 comments · May be fixed by #201

Comments

@ericphanson
Copy link
Contributor

It is very easy to cause a stackoverflow from:

find_intersections(x, y) = find_intersections(vcat(x), vcat(y))

In my case I had TimeSpans because I forgot to convert them to intervals first.

I believe the intention of this code is to collect any iterators so we get vectors to hit the next method,

function find_intersections(x::AbstractVector{<:AbstractInterval}, y::AbstractVector{<:AbstractInterval})
. (I'm not sure why 1-arg vcat would be used over collect but I don't think that's the problem here).

However:

  • dispatching on the eltype of a container isn't good practice, because valid containers like Any[Interval(1,2)] won't get hit (and vcat doesn't help).
  • if, like in my case, you don't have valid intervals, you should get an error, not a stackoverflow

This is extra annoying on MacOS because of the longstanding Julia issue where stackoverflows don't error properly on MacOS.

The easiest fix for the stackoverflow would be to remove the first method, however that would break any code that relies on find_intersections doing this collecting for them. I think a fix that preserves this behavior could look like:

find_intersections(x, y) = _find_intersections(collect(x), collect(y))
find_intersections(x::AbstractVector{<:AbstractInterval}, y::AbstractVector{<:AbstractInterval})  =  _find_intersections(x, y)

and then defining

function _find_intersections(x,y)
   ...
end

with what is currently in the method at

function find_intersections(x::AbstractVector{<:AbstractInterval}, y::AbstractVector{<:AbstractInterval})
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant