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

Union types turn into Any when splatted #26610

Closed
bramtayl opened this issue Mar 25, 2018 · 3 comments · Fixed by #26628
Closed

Union types turn into Any when splatted #26610

bramtayl opened this issue Mar 25, 2018 · 3 comments · Fixed by #26628

Comments

@bramtayl
Copy link
Contributor

t = Tuple{Int,String,Union{Missing, Float64}}[(1, "a", missing), (2, "b", 2.0)]
test(t) = Base.tail(first(t))
@code_warntype test(t)
# Tuple{String,Any}
@bramtayl
Copy link
Contributor Author

bramtayl commented Mar 25, 2018

Further reduction:

t = Tuple{Int, Union{Missing, Float64}}[(1, 2.0)]
argtail(x, rest...) = rest
test(t) = argtail(first(t)...)
@code_warntype test(t)

@bramtayl
Copy link
Contributor Author

bramtayl commented Mar 25, 2018

This solves it:

macro tail(is::Int...)
    esc(:(begin 
        $(map(is) do i
            Ts = map(j -> Symbol("T$j"), 1:i)
            :(tail(t::Tuple{$(Ts...)}) where {$(Ts...)} =
                ($(map(j -> :(t[$j]), 2:i)...),))
        end...)
    end))
end

@tail 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

But I think it's only a band-aid over the loss of type information caused by splatting.

@bramtayl
Copy link
Contributor Author

Is this something that's on purpose? If Union{Missing, T} types are unsplattable, it makes them almost a no-go.

@bramtayl bramtayl changed the title Inference failure in Base.tail Union types turn into Any when splatted Mar 26, 2018
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