Skip to content

Commit

Permalink
Merge pull request #15 from tkoolen/fix-map-ambiguity
Browse files Browse the repository at this point in the history
Fix map! ambiguity.
  • Loading branch information
tkoolen authored Sep 21, 2017
2 parents 307e801 + 35bc8f6 commit 0c3b3c6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/TypeSortedCollections.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Base.@pure num_types(::Type{<:TypeSortedCollection{<:Any, N}}) where {N} = N
num_types(x::TypeSortedCollection) = num_types(typeof(x))

const TSCOrAbstractVector{N} = Union{<:TypeSortedCollection{<:Any, N}, AbstractVector}
const TSCOrAbstractArray{N} = Union{<:TypeSortedCollection{<:Any, N}, AbstractArray}

Base.isempty(x::TypeSortedCollection) = all(isempty, x.data)
Base.empty!(x::TypeSortedCollection) = foreach(empty!, x.data)
Expand Down Expand Up @@ -131,7 +132,7 @@ 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, dest::TSCOrAbstractVector{N}, args::TSCOrAbstractVector{N}...) where {N}
@generated function Base.map!(f, dest::TSCOrAbstractArray{N}, args::TSCOrAbstractArray{N}...) where {N} # TSCOrAbstract*Array* to avoid ambiguities with map!(f, ::AbstractArray, ::AbstractArray...)
expr = Expr(:block)
push!(expr.args, :(Base.@_inline_meta))
push!(expr.args, :(leading_tsc = first_tsc(dest, args...)))
Expand Down
4 changes: 1 addition & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ g(x::Int64, y1::Int64, y2::Float64) = x - y1 * y2
end

@testset "ambiguities" begin
base_ambiguities = detect_ambiguities(Base, Core)
tsc_ambiguities = setdiff(detect_ambiguities(TypeSortedCollections, Base, Core), base_ambiguities)
@test isempty(tsc_ambiguities)
@test isempty(detect_ambiguities(Base, Core, TypeSortedCollections))
end

@testset "general collection interface" begin
Expand Down

0 comments on commit 0c3b3c6

Please sign in to comment.