Skip to content

Commit f814101

Browse files
nsajkoKristofferC
authored andcommitted
fix special function ::Real fallback stack overflow (#57790)
Fixes #57789 (cherry picked from commit 6817691)
1 parent c0c3e51 commit f814101

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

base/math.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1574,7 +1574,7 @@ for f in (:sin, :cos, :tan, :asin, :atan, :acos,
15741574
:exponent, :sqrt, :cbrt, :sinpi, :cospi, :sincospi, :tanpi)
15751575
@eval function ($f)(x::Real)
15761576
xf = float(x)
1577-
x === xf && throw(MethodError($f, (x,)))
1577+
xf isa typeof(x) && throw(MethodError($f, (x,)))
15781578
return ($f)(xf)
15791579
end
15801580
@eval $(f)(::Missing) = missing

test/math.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,6 +1455,14 @@ end
14551455
@test 8.758520413376658e-5^70.55863059215994 == 5.052076767078296e-287
14561456
end
14571457

1458+
@testset "special function `::Real` fallback shouldn't recur without bound, issue #57789" begin
1459+
mutable struct Issue57789 <: Real end
1460+
Base.float(::Issue57789) = Issue57789()
1461+
for f (sin, sinpi, log, exp)
1462+
@test_throws MethodError f(Issue57789())
1463+
end
1464+
end
1465+
14581466
# Test that sqrt behaves correctly and doesn't exhibit fp80 double rounding.
14591467
# This happened on old glibc versions.
14601468
# Test case from https://sourceware.org/bugzilla/show_bug.cgi?id=14032.

0 commit comments

Comments
 (0)