From ec689e0d2fa8ae0688da27b5b82ce95286ffc8b9 Mon Sep 17 00:00:00 2001 From: Guillaume Dalle <22795598+gdalle@users.noreply.github.com> Date: Tue, 4 Jul 2023 15:25:52 +0200 Subject: [PATCH 1/3] Fix weird dispatch of * with zero arguments --- stdlib/LinearAlgebra/src/givens.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stdlib/LinearAlgebra/src/givens.jl b/stdlib/LinearAlgebra/src/givens.jl index c37df41f9567c..cd37745aaef74 100644 --- a/stdlib/LinearAlgebra/src/givens.jl +++ b/stdlib/LinearAlgebra/src/givens.jl @@ -417,7 +417,9 @@ function *(G1::Givens{S}, G2::Givens{T}) where {S,T} TS = promote_type(T, S) Rotation{TS}([convert(AbstractRotation{TS}, G2), convert(AbstractRotation{TS}, G1)]) end -*(G::Givens{T}...) where {T} = Rotation([reverse(G)...]) +function *(G::Givens, Gs::Givens...) + return Rotation([reverse(Gs)..., G]) +end function *(G::Givens{S}, R::Rotation{T}) where {S,T} TS = promote_type(T, S) Rotation(vcat(convert(AbstractRotation{TS}, R).rotations, convert(AbstractRotation{TS}, G))) From edde4c2e567d65872c08d24a2adbd57c2029b64f Mon Sep 17 00:00:00 2001 From: Guillaume Dalle <22795598+gdalle@users.noreply.github.com> Date: Tue, 4 Jul 2023 16:16:26 +0200 Subject: [PATCH 2/3] Enforce coherence of Givens type parameter --- stdlib/LinearAlgebra/src/givens.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/LinearAlgebra/src/givens.jl b/stdlib/LinearAlgebra/src/givens.jl index cd37745aaef74..4668d5f542a91 100644 --- a/stdlib/LinearAlgebra/src/givens.jl +++ b/stdlib/LinearAlgebra/src/givens.jl @@ -417,7 +417,7 @@ function *(G1::Givens{S}, G2::Givens{T}) where {S,T} TS = promote_type(T, S) Rotation{TS}([convert(AbstractRotation{TS}, G2), convert(AbstractRotation{TS}, G1)]) end -function *(G::Givens, Gs::Givens...) +function *(G::Givens{T}, Gs::Givens{T}...) where {T} return Rotation([reverse(Gs)..., G]) end function *(G::Givens{S}, R::Rotation{T}) where {S,T} From 407030f393d1dac554a15ea25b576710c93e27c3 Mon Sep 17 00:00:00 2001 From: Guillaume Dalle <22795598+gdalle@users.noreply.github.com> Date: Tue, 4 Jul 2023 18:18:01 +0200 Subject: [PATCH 3/3] Add tests --- test/operators.jl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/operators.jl b/test/operators.jl index 46cf6c7526299..715212a80a54f 100644 --- a/test/operators.jl +++ b/test/operators.jl @@ -154,6 +154,13 @@ Base.convert(::Type{T19714}, ::Int) = T19714() Base.promote_rule(::Type{T19714}, ::Type{Int}) = T19714 @test T19714()/1 === 1/T19714() === T19714() +@testset "operators with zero argument" begin + @test_throws(MethodError, +()) + @test_throws(MethodError, *()) + @test isempty(methods(+, ())) + @test isempty(methods(*, ())) +end + # pr #17155 and #33568 @testset "function composition" begin @test (uppercase∘(x->string(x,base=16)))(239487) == "3A77F"