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

Unions with empty tuple causes error in conversions #28915

Closed
arbenson opened this issue Aug 27, 2018 · 4 comments
Closed

Unions with empty tuple causes error in conversions #28915

arbenson opened this issue Aug 27, 2018 · 4 comments
Assignees
Labels
domain:types and dispatch Types, subtyping and method dispatch

Comments

@arbenson
Copy link

Minimal working example:

TupleType = Union{NTuple{0,Int64},NTuple{1,Int64}}
convert(TupleType, (1,))

The error is

ERROR: BoundsError: attempt to access Tuple{}
at index [1]
Stacktrace:
[1] tuple_type_head(::Type) at ./essentials.jl:175
[2] convert(::Type{Union{Tuple{}, Tuple{Int64}}}, ::Tuple{Int64}) at ./essentials.jl:269
[3] push!(::Array{Union{Tuple{}, Tuple{Int64}},1}, ::Tuple{Int64}) at ./array.jl:855
[4] top-level scope at none:0

This error comes up when I want to push tuples of type TupleType to, say, an instance of Vector{TupleTyple}.

This was not a problem in 0.6.2 but is a problem in 1.0.

julia> versioninfo()
Julia Version 1.0.0
Commit 5d4eaca (2018-08-08 20:58 UTC)
Platform Info:
OS: macOS (x86_64-apple-darwin14.5.0)
CPU: Intel(R) Core(TM) i7-7920HQ CPU @ 3.10GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.0 (ORCJIT, skylake)

@Sacha0
Copy link
Member

Sacha0 commented Aug 28, 2018

(Great to see you here Austin! :) 👋)

@JeffBezanson JeffBezanson self-assigned this Aug 29, 2018
@JeffBezanson JeffBezanson added the domain:types and dispatch Types, subtyping and method dispatch label Aug 29, 2018
@JeffBezanson
Copy link
Sponsor Member

In this case, the conversion is an identity conversion. Out of curiosity, do you need it to work more generally as well, e.g. convert(TupleType, (1.0,))?

@arbenson
Copy link
Author

No, I wouldn't actually need the more general type conversion of Float to Int for my use case.

My use case is a small library I built for small fixed-size sets. It is used for datasets consisting of a large number of sets of Integers, but each set is small (cardinality between 0 and 5), and the algorithms perform lots of intersections and set creations. I was abstracting the set structure by these tuples (and keeping them ordered internally), which made the set intersections much faster and removed some of the overhead in instantiating Set{Int64}().

@arbenson
Copy link
Author

arbenson commented Sep 4, 2018

Thanks, @JeffBezanson !

KristofferC pushed a commit that referenced this issue Sep 8, 2018
KristofferC pushed a commit that referenced this issue Sep 8, 2018
KristofferC pushed a commit that referenced this issue Feb 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

No branches or pull requests

3 participants