Skip to content

Commit aa06976

Browse files
authored
make typejoin nothrow (#58578)
Fixes #50985
1 parent b61664e commit aa06976

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
@@ -309,22 +309,9 @@ end |> only == Type{typejoin(Int, UInt)}
309309
typejoin(Int, UInt, Float64)
310310
end |> only == Type{typejoin(Int, UInt, Float64)}
311311

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

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

0 commit comments

Comments
 (0)