@@ -335,17 +335,19 @@ const _promote_type_binary_detected_infinite_recursion_exception = let
335
335
s = " `promote_type`: detected unbounded recursion caused by faulty `promote_rule` logic"
336
336
ArgumentError (s)
337
337
end
338
+ function _promote_type_binary_err_giving_up ()
339
+ @noinline
340
+ throw (_promote_type_binary_recursion_depth_limit_exception)
341
+ end
342
+ function _promote_type_binary_err_detected_infinite_recursion ()
343
+ @noinline
344
+ throw (_promote_type_binary_detected_infinite_recursion_exception)
345
+ end
346
+ function _promote_type_binary_detect_loop (T:: Type , S:: Type , A:: Type , B:: Type )
347
+ onesided (T:: Type , S:: Type , A:: Type , B:: Type ) = _types_are_equal (T, A) && _types_are_equal (S, B)
348
+ onesided (T, S, A, B) || onesided (T, S, B, A)
349
+ end
338
350
function _promote_type_binary (T:: Type , S:: Type , recursion_depth_limit:: Tuple{Vararg{Nothing}} )
339
- function err_giving_up ()
340
- @noinline
341
- throw (_promote_type_binary_recursion_depth_limit_exception)
342
- end
343
- function err_detected_infinite_recursion ()
344
- @noinline
345
- throw (_promote_type_binary_detected_infinite_recursion_exception)
346
- end
347
- detect_loop_onesided (T:: Type , S:: Type , A:: Type , B:: Type ) = _types_are_equal (T, A) && _types_are_equal (S, B)
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
351
# Try promote_rule in both orders.
350
352
ts = promote_rule (T, S)
351
353
st = promote_rule (S, T)
@@ -362,13 +364,13 @@ function _promote_type_binary(T::Type, S::Type, recursion_depth_limit::Tuple{Var
362
364
if st_is_bottom || _types_are_equal (st, ts)
363
365
return ts
364
366
end
365
- if detect_loop (T, S, ts, st)
367
+ if _promote_type_binary_detect_loop (T, S, ts, st)
366
368
# This is not strictly necessary, as we already limit the recursion depth, but
367
369
# makes for nicer UX.
368
- err_detected_infinite_recursion ()
370
+ _promote_type_binary_err_detected_infinite_recursion ()
369
371
end
370
372
if recursion_depth_limit === ()
371
- err_giving_up ()
373
+ _promote_type_binary_err_giving_up ()
372
374
end
373
375
l = tail (recursion_depth_limit)
374
376
_promote_type_binary (ts, st, l)
0 commit comments