# Union and intersect with unexpected return types

**URL:** <https://discourse.julialang.org/t/union-and-intersect-with-unexpected-return-types/5222>\
**Category:** Internals & Design\
**Tags:** bug\
**Created:** [August 4, 2017, 1:27pm UTC](https://discourse.julialang.org/t/union-and-intersect-with-unexpected-return-types/5222 "2017-08-04T13:27:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![klacru](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/klacru/32/27890_2.png) [@klacru](https://discourse.julialang.org/u/klacru)\
**Post date:** [August 4, 2017, 1:27pm UTC](https://discourse.julialang.org/t/union-and-intersect-with-unexpected-return-types/5222/1 "2017-08-04T13:27:06Z")

</div>

Tried the following:

```julia
  | | |_| | | | (_| | | 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
julia> intersect(IntSet([1,42]), Set(Int16[1,2,3]))
IntSet([1])

```

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

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

```

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

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

```

which is responsible for the `Array` return type.

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [August 4, 2017, 7:48pm UTC](https://discourse.julialang.org/t/union-and-intersect-with-unexpected-return-types/5222/2 "2017-08-04T19:48:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![klacru](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/klacru/32/27890_2.png) [@klacru](https://discourse.julialang.org/u/klacru)\
**Post date:** [August 5, 2017, 9:47am UTC](https://discourse.julialang.org/t/union-and-intersect-with-unexpected-return-types/5222/3 "2017-08-05T09:47:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [August 5, 2017, 10:50am UTC](https://discourse.julialang.org/t/union-and-intersect-with-unexpected-return-types/5222/4 "2017-08-05T10:50:40Z")

</div>

Start [here](https://github.com/JuliaLang/julia/blob/master/CONTRIBUTING.md), 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…

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [August 14, 2017, 3:38am UTC](https://discourse.julialang.org/t/union-and-intersect-with-unexpected-return-types/5222/5 "2017-08-14T03:38:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![klacru](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/klacru/32/27890_2.png) [@klacru](https://discourse.julialang.org/u/klacru)\
**Post date:** [August 14, 2017, 6:37am UTC](https://discourse.julialang.org/t/union-and-intersect-with-unexpected-return-types/5222/6 "2017-08-14T06:37:16Z")

</div>

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