From 985e95d67202e7406be8554ae7e08a8ff9bf5e90 Mon Sep 17 00:00:00 2001 From: Twan Koolen Date: Sun, 13 Aug 2017 17:35:05 -0400 Subject: [PATCH] Fix ambiguities with Base.map!, add test. --- src/TypeSortedCollections.jl | 8 +++----- test/runtests.jl | 10 +++++++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/TypeSortedCollections.jl b/src/TypeSortedCollections.jl index b139593..7cc7659 100644 --- a/src/TypeSortedCollections.jl +++ b/src/TypeSortedCollections.jl @@ -115,16 +115,14 @@ end @inline indices_match(vali::Val, indices::Vector{Int}, a1, as...) = indices_match(vali, indices, a1) && indices_match(vali, indices, as...) @noinline indices_match_fail() = throw(ArgumentError("Indices of TypeSortedCollections do not match.")) -@generated function Base.map!(f, As::Union{<:TypeSortedCollection{<:Any, N}, AbstractVector}...) where {N} +@generated function Base.map!(f, dest::Union{TypeSortedCollection{<:Any, N}, AbstractArray}, args::Union{TypeSortedCollection{<:Any, N}, AbstractArray}...) where {N} expr = Expr(:block) - push!(expr.args, :(leading_tsc = first_tsc(As...))) - push!(expr.args, :(dest = As[1])) - push!(expr.args, :(args = Base.tail(As))) + push!(expr.args, :(leading_tsc = first_tsc(dest, args...))) for i = 1 : N vali = Val(i) push!(expr.args, quote let inds = leading_tsc.indices[$i] - @boundscheck indices_match($vali, inds, As...) || indices_match_fail() + @boundscheck indices_match($vali, inds, dest, args...) || indices_match_fail() for j in linearindices(inds) vecindex = inds[j] _setindex!($vali, j, vecindex, dest, f(_getindex_all($vali, j, vecindex, args...)...)) diff --git a/test/runtests.jl b/test/runtests.jl index 9223469..2b7e275 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,9 @@ -using TypeSortedCollections using Base.Test +base_ambiguities = detect_ambiguities(Base, Core) + +using TypeSortedCollections + module M f(x::Int64) = 3 * x f(x::Float64) = round(Int64, x / 2) @@ -11,6 +14,11 @@ g(x::Int64, y1::Float64, y2::Float64) = x * y1 - y2 g(x::Float64, y1::Float64, y2::Float64) = x + y1 - y2 end +@testset "ambiguities" begin + tsc_ambiguities = setdiff(detect_ambiguities(TypeSortedCollections, Base, Core), base_ambiguities) + @test isempty(tsc_ambiguities) +end + @testset "general collection interface" begin x = Number[3.; 4; 5] sortedx = TypeSortedCollection(x)