Union and intersect with unexpected return types

Tried the following:

  | | |_| | | | (_| |  |  Version 0.6.0 (2017-06-19 13:05 UTC)
 _/ |\__'_|_|_|\__'_|  |  
|__/                   |  x86_64-redhat-linux

julia> union(Set(Int16[1,2,3]), IntSet([1,42]))
4-element Array{Int64,1}:
  2
  3
  1
 42

julia> intersect(Set(Int16[1,2,3]), IntSet([1,42]))
1-element Array{Int64,1}:
 1

and was confused, why didn’t I see a Set, or IntSet but a Vector?
Interchanging the arguments helped, so that seemed not a design decision.

julia> intersect(IntSet([1,42]), Set(Int16[1,2,3]))
IntSet([1])

I found the bugs in base/set.jl:54 and :69

function union(s::Set, sets::Set...)

I think, the second Set should be AbstractSet there, otherwise the method falls back to

intersect(v1, vs...) in Base at array.jl:1854

which is responsible for the Array return type.

There does seem to be an issue here. I suggest you make a pull request with the suggested change and some tests.

Yes, I will do. But as I am rather novice, I need instructions how to set up a pull request. Unfortunately I could not find any hint in this forum and have to ask for a link.

1 Like

Start here, perhaps. It’s usually a good idea to get started and then ask for help when you get stuck, since then there’s some context and detail. Also, the Gitter/IRC and Slack channels have operators waiting for your call…

1 Like

Please do file an issue at least. If there’s already an issue, please link to it here so that one can follow the breadcrumbs.

This issue has bee fixed and merged into master:
https://github.com/JuliaLang/julia/pull/23139

3 Likes