Skip to content

Commit

Permalink
fix #41489: inference of +(::Rational, Rational) (#41491)
Browse files Browse the repository at this point in the history
* fix #41489: inference of `+(::Rational, Rational)`

* implement review comments
  • Loading branch information
simeonschaub committed Jul 7, 2021
1 parent 8efdf85 commit cf4e1c4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/rational.jl
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ function -(x::Rational{T}) where T<:Unsigned
end

function +(x::Rational, y::Rational)
xp, yp = promote(x, y)
xp, yp = promote(x, y)::NTuple{2,Rational}
if isinf(x) && x == y
return xp
end
Expand All @@ -289,7 +289,7 @@ function +(x::Rational, y::Rational)
end

function -(x::Rational, y::Rational)
xp, yp = promote(x, y)
xp, yp = promote(x, y)::NTuple{2,Rational}
if isinf(x) && x == -y
return xp
end
Expand Down
8 changes: 8 additions & 0 deletions test/rational.jl
Original file line number Diff line number Diff line change
Expand Up @@ -622,3 +622,11 @@ end
@testset "Rational{T} with non-concrete T (issue #41222)" begin
@test @inferred(Rational{Integer}(2,3)) isa Rational{Integer}
end

@testset "issue #41489" begin
@test Core.Compiler.return_type(+, NTuple{2, Rational}) == Rational
@test Core.Compiler.return_type(-, NTuple{2, Rational}) == Rational

A=Rational[1 1 1; 2 2 2; 3 3 3]
@test @inferred(A*A) isa Matrix{Rational}
end

0 comments on commit cf4e1c4

Please sign in to comment.