From 1e3b270fc050aa1d43e119ab8d60d645b5fce01a Mon Sep 17 00:00:00 2001 From: Sebastian Stock <42280794+sostock@users.noreply.github.com> Date: Mon, 25 Oct 2021 16:45:51 +0200 Subject: [PATCH] Resolve method ambiguity (#495) --- src/range.jl | 4 ++++ test/runtests.jl | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/range.jl b/src/range.jl index fb864cc1..b42dffe7 100644 --- a/src/range.jl +++ b/src/range.jl @@ -108,3 +108,7 @@ broadcasted(::DefaultArrayStyle{1}, ::typeof(*), r::StepRangeLen{T}, x::Abstract broadcasted(DefaultArrayStyle{1}(), *, r, ustrip(x)) * unit(x) broadcasted(::DefaultArrayStyle{1}, ::typeof(*), x::AbstractQuantity, r::StepRangeLen{T}) where T = broadcasted(DefaultArrayStyle{1}(), *, ustrip(x), r) * unit(x) +broadcasted(::DefaultArrayStyle{1}, ::typeof(*), r::LinRange, x::AbstractQuantity) = + LinRange(r.start*x, r.stop*x, r.len) +broadcasted(::DefaultArrayStyle{1}, ::typeof(*), x::AbstractQuantity, r::LinRange) = + LinRange(x*r.start, x*r.stop, r.len) diff --git a/test/runtests.jl b/test/runtests.jl index 9cd426a3..602840e5 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1164,6 +1164,10 @@ end @test *(1:5, mm, s^-1, mol^-1) === 1mm*s^-1*mol^-1:1mm*s^-1*mol^-1:5mm*s^-1*mol^-1 @test @inferred((0:2) * 3f0m) === StepRangeLen{typeof(0f0m)}(0.0m, 3.0m, 3) # issue #477 @test @inferred(3f0m * (0:2)) === StepRangeLen{typeof(0f0m)}(0.0m, 3.0m, 3) # issue #477 + @test @inferred((0f0:2f0) * 3f0m) === 0f0m:3f0m:6f0m + @test @inferred(3f0m * (0.0:2.0)) === 0.0m:3.0m:6.0m + @test @inferred(LinRange(0f0, 1f0, 3) * 3f0m) === LinRange(0f0m, 3f0m, 3) + @test @inferred(3f0m * LinRange(0.0, 1.0, 3)) === LinRange(0.0m, 3.0m, 3) @test @inferred(1.0s * range(0.1, step=0.1, length=3)) === @inferred(range(0.1, step=0.1, length=3) * 1.0s) end end