Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions base/promotion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ typejoin(@nospecialize(t), @nospecialize(s), @nospecialize(u)) = (@_foldable_met
typejoin(@nospecialize(t), @nospecialize(s), @nospecialize(u), ts...) = (@_foldable_meta; @_nospecializeinfer_meta; afoldl(typejoin, typejoin(t, s, u), ts...))
function typejoin(@nospecialize(a), @nospecialize(b))
@_foldable_meta
@_nothrow_meta
@_nospecializeinfer_meta
if isa(a, TypeVar)
return typejoin(a.ub, b)
elseif isa(b, TypeVar)
return typejoin(a, b.ub)
elseif a === b
return a
elseif !isa(a, Type) || !isa(b, Type)
return Any
Comment on lines +32 to +35
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it intentional that typejoin(3, 3, 3) returns 3, instead of Any?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These seem a bit inconsistent, I guess:

julia> typejoin(3, 3, 3)
3

julia> typejoin(3, 3, 3.0)
Any

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are both correct

elseif a <: b
return b
elseif b <: a
Expand Down
19 changes: 3 additions & 16 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -309,22 +309,9 @@ end |> only == Type{typejoin(Int, UInt)}
typejoin(Int, UInt, Float64)
end |> only == Type{typejoin(Int, UInt, Float64)}

let res = @test_throws TypeError let
Base.Experimental.@force_compile
typejoin(1, 2)
nothing
end
err = res.value
@test err.func === :<:
end
let res = @test_throws TypeError let
Base.Experimental.@force_compile
typejoin(1, 2, 3)
nothing
end
err = res.value
@test err.func === :<:
end
@test typejoin(1, 2) === Any
@test typejoin(1, 2, 3) === Any
@test typejoin(Int, Int, 3) === Any

# promote_typejoin returns a Union only with Nothing/Missing combined with concrete types
for T in (Nothing, Missing)
Expand Down