@@ -309,6 +309,16 @@ function promote_type(::Type{T}, ::Type{S}) where {T,S}
309
309
types_are_equal (:: Type{Typ} , :: Type{Typ} ) where {Typ} = true
310
310
is_bottom (:: Type ) = false
311
311
is_bottom (:: Type{Bottom} ) = true
312
+ function throw_conflicting_promote_rules ((@nospecialize i1:: Type ), (@nospecialize i2:: Type ), (@nospecialize left:: Type ), (@nospecialize right:: Type ))
313
+ @noinline
314
+ s = LazyString (" `promote_type(" , i1, " , " , i2, " )` failed, there are conflicting `promote_rule` definitions for types " , left, " , " , right)
315
+ throw (ArgumentError (s))
316
+ end
317
+ function throw_gave_up ((@nospecialize i1:: Type ), (@nospecialize i2:: Type ), (@nospecialize left:: Type ), (@nospecialize right:: Type ))
318
+ @noinline
319
+ s = LazyString (" `promote_type(" , i1, " , " , i2, " )` failed, ended up with (" , left, " , " , right, " ), check for faulty `promote_rule` methods" )
320
+ throw (ArgumentError (s))
321
+ end
312
322
left = T
313
323
right = S
314
324
for _ ∈ 1 : 1000
@@ -321,9 +331,7 @@ function promote_type(::Type{T}, ::Type{S}) where {T,S}
321
331
loop_is_detected_1 = types_are_equal (left, a) && types_are_equal (right, b)
322
332
loop_is_detected_2 = types_are_equal (left, b) && types_are_equal (right, a)
323
333
if loop_is_detected_1 || loop_is_detected_2
324
- let s = LazyString (" `promote_type(" , T, " , " , S, " )` failed, there are conflicting `promote_rule` definitions for types " , a, " , " , b)
325
- throw (ArgumentError (s))
326
- end
334
+ throw_conflicting_promote_rules (T, S, left, right)
327
335
end
328
336
if is_bottom (a) && is_bottom (b)
329
337
# If no `promote_rule` is defined, both directions give `Bottom`. In that
@@ -338,9 +346,7 @@ function promote_type(::Type{T}, ::Type{S}) where {T,S}
338
346
elseif is_bottom (right)
339
347
left
340
348
else
341
- let s = LazyString (" `promote_type(" , T, " , " , S, " )` failed, ended up with (" , left, " , " , right, " ), check for faulty `promote_rule` methods" )
342
- throw (ArgumentError (s))
343
- end
349
+ throw_gave_up (T, S, left, right)
344
350
end
345
351
end
346
352
0 commit comments