diff --git a/base/abstractarray.jl b/base/abstractarray.jl index 174d60905923c..716f9e35fe692 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -1609,7 +1609,12 @@ _div(ind, d::Integer) = div(ind, d), 1, d _div(ind, r::AbstractUnitRange) = (d = unsafe_length(r); (div(ind, d), first(r), d)) # Vectorized forms -function sub2ind{N,T<:Integer}(inds::Union{Dims{N},Indices{N}}, I::AbstractVector{T}...) +function sub2ind{T<:Integer}(inds::Indices{1}, I1::AbstractVector{T}, I::AbstractVector{T}...) + throw(ArgumentError("Linear indexing is not defined for one-dimensional arrays")) +end +sub2ind{T<:Integer}(inds::Tuple{OneTo}, I1::AbstractVector{T}, I::AbstractVector{T}...) = _sub2ind_vecs(inds, I1, I...) +sub2ind{T<:Integer}(inds::Union{DimsInteger,Indices}, I1::AbstractVector{T}, I::AbstractVector{T}...) = _sub2ind_vecs(inds, I1, I...) +function _sub2ind_vecs(inds, I::AbstractVector...) I1 = I[1] Iinds = indices1(I1) for j = 2:length(I) @@ -1633,7 +1638,7 @@ sub2ind_vec(inds, i, I) = (@_inline_meta; _sub2ind_vec(inds, (), i, I...)) _sub2ind_vec(inds, out, i, I1, I...) = (@_inline_meta; _sub2ind_vec(inds, (out..., I1[i]), i, I...)) _sub2ind_vec(inds, out, i) = (@_inline_meta; sub2ind(inds, out...)) -function ind2sub{N,T<:Integer}(inds::Union{Dims{N},Indices{N}}, ind::AbstractVector{T}) +function ind2sub{N,T<:Integer}(inds::Union{DimsInteger{N},Indices{N}}, ind::AbstractVector{T}) M = length(ind) t = ntuple(n->similar(ind),Val{N}) for (i,idx) in enumerate(ind) # FIXME: change to eachindexvalue diff --git a/test/ambiguous.jl b/test/ambiguous.jl index 37a8135f2db88..451ffd03f85c9 100644 --- a/test/ambiguous.jl +++ b/test/ambiguous.jl @@ -186,4 +186,21 @@ immutable T end end @test length(detect_ambiguities(Ambig7)) == 1 +module Ambig8 +using Base: DimsInteger, Indices +g18307{T<:Integer}(::Union{Indices,Dims}, I::AbstractVector{T}...) = 1 +g18307(::DimsInteger) = 2 +g18307(::DimsInteger, I::Integer...) = 3 +end +try + # want this to be a test_throws MethodError, but currently it's not (see #18307) + Ambig8.g18307((1,)) +catch err + if isa(err, MethodError) + error("Test correctly returned a MethodError, please change to @test_throws MethodError") + else + rethrow(err) + end +end + nothing