Skip to content

ill-formed output produced by broadcast operations on empty arrays #47845

Open
@thautwarm

Description

@thautwarm

The following behaviour can be reproduced in Julia v1.8-v1.10.0-DEV.

julia> Int[] .+ String[]
Union{}[]

julia> Int[] .* String[]
Union{}[]

It can be also observed at map operations:

 julia> map(+, Int[], String[])
Union{}[]

This is caused by missing some necessary checks when using type inference tricks to pre-decide the element type. If the type level computation gets us a bottom type, raising an exception looks more appropriate:

R = Base.return_type(f, Tuple{A, B})
R == Base.Bottom && error("invalid operation ...")
# do stuff

Metadata

Metadata

Assignees

No one assigned

    Labels

    broadcastApplying a function over a collection

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions