Skip to content

Commit ac93888

Browse files
simeonschaubKristofferC
authored andcommitted
fix #41489: inference of +(::Rational, Rational) (#41491)
* fix #41489: inference of `+(::Rational, Rational)` * implement review comments (cherry picked from commit cf4e1c4)
1 parent db05fae commit ac93888

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

base/rational.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ function -(x::Rational{T}) where T<:Unsigned
280280
end
281281

282282
function +(x::Rational, y::Rational)
283-
xp, yp = promote(x, y)
283+
xp, yp = promote(x, y)::NTuple{2,Rational}
284284
if isinf(x) && x == y
285285
return xp
286286
end
@@ -289,7 +289,7 @@ function +(x::Rational, y::Rational)
289289
end
290290

291291
function -(x::Rational, y::Rational)
292-
xp, yp = promote(x, y)
292+
xp, yp = promote(x, y)::NTuple{2,Rational}
293293
if isinf(x) && x == -y
294294
return xp
295295
end

test/rational.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,3 +622,11 @@ end
622622
@testset "Rational{T} with non-concrete T (issue #41222)" begin
623623
@test @inferred(Rational{Integer}(2,3)) isa Rational{Integer}
624624
end
625+
626+
@testset "issue #41489" begin
627+
@test Core.Compiler.return_type(+, NTuple{2, Rational}) == Rational
628+
@test Core.Compiler.return_type(-, NTuple{2, Rational}) == Rational
629+
630+
A=Rational[1 1 1; 2 2 2; 3 3 3]
631+
@test @inferred(A*A) isa Matrix{Rational}
632+
end

0 commit comments

Comments
 (0)