JuliaArrays / StaticArrays.jl

Statically sized arrays for Julia
Other
764 stars 149 forks source link

Concatenating arrays of FieldVectors fails due to ambiguity #146

Closed ajkeller34 closed 7 years ago

ajkeller34 commented 7 years ago

On Julia version 0.6.0-pre.beta.293 (2017-04-23 19:58 UTC), and master of StaticArrays:

julia> struct Point{T} <: FieldVector{T}
         x::T
         y::T
       end

julia> [[Point(3,4)]; [Point(1,2), Point(3,4)]]
ERROR: MethodError: Base.unsafe_convert(::Type{Ptr{Void}}, ::Ptr{Point{Int64}}) is ambiguous. Candidates:
  unsafe_convert(::Type{P}, x::Ptr) where P<:Ptr in Base at essentials.jl:154
  unsafe_convert(::Type{Ptr{T}}, m::Ref{FV}) where {T, FV<:StaticArrays.FieldVector} in StaticArrays at /Users/ajkeller/.julia/v0.6/StaticArrays/src/FieldVector.jl:30
Possible fix, define
  unsafe_convert(::Type{Ptr{T}}, ::Ptr{FV<:StaticArrays.FieldVector})
Stacktrace:
 [1] vcat(::Array{Point{Int64},1}, ::Array{Point{Int64},1}) at ./array.jl:1120

This works fine on Julia 0.5.1 and StaticArrays 0.3.1.

andyferris commented 7 years ago

I'm a little surprised that this method is necessary. We should run the ambiguity detection tool, I guess...

Evizero commented 7 years ago

We should run the ambiguity detection tool

There is some example code in ImageTransformations that Prof Holy implemented here, that could be useful as template.

# ...
refambs = detect_ambiguities(CoordinateTransformations, Base, Core)
using ImageTransformations
ambs = detect_ambiguities(ImageTransformations, CoordinateTransformations, Base, Core)
@test isempty(setdiff(ambs, refambs))
# ...
andyferris commented 7 years ago

Bugger

julia> Base.Test.detect_ambiguities(StaticArrays, Base, Core)
Skipping Base.<|
ERROR: TypeError: apply_type: in Vararg count, expected Int64, got Type{Any}
Stacktrace:
 [1] #isambiguous#23(::Bool, ::Function, ::Method, ::Method) at ./reflection.jl:972
 [2] (::Base.#kw##isambiguous)(::Array{Any,1}, ::Base.#isambiguous, ::Method, ::Method) at ./<missing>:0
 [3] #detect_ambiguities#20(::Bool, ::Bool, ::Void, ::Function, ::Module, ::Vararg{Module,N} where N) at ./test.jl:1158
 [4] detect_ambiguities(::Module, ::Vararg{Module,N} where N) at ./test.jl:1133