Skip to content

Commit 6e8340b

Browse files
vtjnashKristofferC
authored andcommitted
make typejoin nothrow (#58578)
Fixes #50985 (cherry picked from commit aa06976)
1 parent 4fc2dea commit 6e8340b

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

base/promotion.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,16 @@ typejoin(@nospecialize(t), @nospecialize(s), @nospecialize(u)) = (@_foldable_met
2323
typejoin(@nospecialize(t), @nospecialize(s), @nospecialize(u), ts...) = (@_foldable_meta; @_nospecializeinfer_meta; afoldl(typejoin, typejoin(t, s, u), ts...))
2424
function typejoin(@nospecialize(a), @nospecialize(b))
2525
@_foldable_meta
26+
@_nothrow_meta
2627
@_nospecializeinfer_meta
2728
if isa(a, TypeVar)
2829
return typejoin(a.ub, b)
2930
elseif isa(b, TypeVar)
3031
return typejoin(a, b.ub)
32+
elseif a === b
33+
return a
34+
elseif !isa(a, Type) || !isa(b, Type)
35+
return Any
3136
elseif a <: b
3237
return b
3338
elseif b <: a

test/core.jl

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -307,22 +307,9 @@ end |> only == Type{typejoin(Int, UInt)}
307307
typejoin(Int, UInt, Float64)
308308
end |> only == Type{typejoin(Int, UInt, Float64)}
309309

310-
let res = @test_throws TypeError let
311-
Base.Experimental.@force_compile
312-
typejoin(1, 2)
313-
nothing
314-
end
315-
err = res.value
316-
@test err.func === :<:
317-
end
318-
let res = @test_throws TypeError let
319-
Base.Experimental.@force_compile
320-
typejoin(1, 2, 3)
321-
nothing
322-
end
323-
err = res.value
324-
@test err.func === :<:
325-
end
310+
@test typejoin(1, 2) === Any
311+
@test typejoin(1, 2, 3) === Any
312+
@test typejoin(Int, Int, 3) === Any
326313

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

0 commit comments

Comments
 (0)