@@ -346,20 +346,22 @@ function _promote_type_binary(T::Type, S::Type, recursion_depth_limit::Tuple{Var
346
346
end
347
347
detect_loop_onesided (T:: Type , S:: Type , A:: Type , B:: Type ) = _types_are_equal (T, A) && _types_are_equal (S, B)
348
348
detect_loop (T:: Type , S:: Type , A:: Type , B:: Type ) = detect_loop_onesided (T, S, A, B) || detect_loop_onesided (T, S, B, A)
349
- if _type_is_bottom (T)
350
- return S
351
- end
352
- if _type_is_bottom (S) || _types_are_equal (S, T)
353
- return T
354
- end
355
349
# Try promote_rule in both orders.
356
350
ts = promote_rule (T, S)
357
351
st = promote_rule (S, T)
358
352
# If no promote_rule is defined, both directions give Bottom. In that
359
353
# case use typejoin on the original types instead.
360
- if _type_is_bottom (st) && _type_is_bottom (ts)
354
+ st_is_bottom = _type_is_bottom (st)
355
+ ts_is_bottom = _type_is_bottom (ts)
356
+ if st_is_bottom && ts_is_bottom
361
357
return typejoin (T, S)
362
358
end
359
+ if ts_is_bottom
360
+ return st
361
+ end
362
+ if st_is_bottom || _types_are_equal (st, ts)
363
+ return ts
364
+ end
363
365
if detect_loop (T, S, ts, st)
364
366
# This is not strictly necessary, as we already limit the recursion depth, but
365
367
# makes for nicer UX.
@@ -385,6 +387,12 @@ const _promote_type_binary_recursion_depth_limit = let
385
387
end
386
388
387
389
function promote_type (:: Type{T} , :: Type{S} ) where {T,S}
390
+ if _type_is_bottom (T)
391
+ return S
392
+ end
393
+ if _type_is_bottom (S) || _types_are_equal (S, T)
394
+ return T
395
+ end
388
396
_promote_type_binary (T, S, _promote_type_binary_recursion_depth_limit)
389
397
end
390
398
0 commit comments