diff --git a/base/rational.jl b/base/rational.jl index ab4e7d6d0abbd..23c9298962f53 100644 --- a/base/rational.jl +++ b/base/rational.jl @@ -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 @@ -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 diff --git a/test/rational.jl b/test/rational.jl index 24b99cdc8b6d9..a329a1ac5f93d 100644 --- a/test/rational.jl +++ b/test/rational.jl @@ -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