Skip to content

Commit 59e5711

Browse files
committed
outline throws
1 parent e16163e commit 59e5711

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

base/promotion.jl

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,16 @@ function promote_type(::Type{T}, ::Type{S}) where {T,S}
309309
types_are_equal(::Type{Typ}, ::Type{Typ}) where {Typ} = true
310310
is_bottom(::Type) = false
311311
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
312322
left = T
313323
right = S
314324
for _ 1:1000
@@ -321,9 +331,7 @@ function promote_type(::Type{T}, ::Type{S}) where {T,S}
321331
loop_is_detected_1 = types_are_equal(left, a) && types_are_equal(right, b)
322332
loop_is_detected_2 = types_are_equal(left, b) && types_are_equal(right, a)
323333
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)
327335
end
328336
if is_bottom(a) && is_bottom(b)
329337
# 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}
338346
elseif is_bottom(right)
339347
left
340348
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)
344350
end
345351
end
346352

0 commit comments

Comments
 (0)