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

Return typing of a function is ignored when calling the map() function on empty objects. #46958

Open
BaileyBox opened this issue Sep 28, 2022 · 3 comments

Comments

@BaileyBox
Copy link

BaileyBox commented Sep 28, 2022

The return types of a function are being ignored when calling the map() function on empty objects.

Here's an example of how this functioned in 1.6 vs 1.8:

Julia 1.6:

julia> function bar(v::Vector{Int})::AbstractArray{Int}
           fill(v[1], (1 for _ in 1:v[1])...)
       end
bar (generic function with 1 method)

julia> map(bar, Vector{Int}[[1]])
1-element Vector{Vector{Int64}}:
 [1]

julia> map(bar, Vector{Int}[[2]])
1-element Vector{Matrix{Int64}}:
 [2]

julia> map(bar, Vector{Int}[])
AbstractArray{Int64, N} where N[]

Julia 1.8:

julia> function bar(v::Vector{Int})::AbstractArray{Int}
           fill(v[1], (1 for _ in 1:v[1])...)
       end
bar (generic function with 1 method)

julia> map(bar, Vector{Int}[[1]])
1-element Vector{Vector{Int64}}:
 [1]

julia> map(bar, Vector{Int}[[2]])
1-element Vector{Matrix{Int64}}:
 [2;;]

julia> map(bar, Vector{Int}[])
Any[]

This was due to the changes introduced where map functions call promote_typejoin_union and return Any instead of the given return type of the function.

This functionality was always the case for broadcast(), but now since map() is following this logic, the return types are ignored on empty objects.

@vtjnash
Copy link
Member

vtjnash commented Sep 28, 2022

xref #46331

@JeffBezanson
Copy link
Member

I must say the logic

    elseif T isa UnionAll
        return Any

is not exactly impressive.

@vtjnash
Copy link
Member

vtjnash commented Oct 1, 2022

Xref f0046a0

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

No branches or pull requests

3 participants