Skip to content

Specificity transitivity errors among convert methods #30114

@Keno

Description

@Keno

The following exhibits lack of transitivity in method specificity:

T1 = Tuple{typeof(convert),Type{Tuple{Vararg{AbstractUnitRange{Int64},N} where N}},CartesianIndices{N,R} where R<:Tuple{Vararg{AbstractUnitRange{Int64},N}}} where N
T2 = Tuple{typeof(convert),Type{T},T} where T<:AbstractArray
T3 = Tuple{typeof(convert),Type{AbstractArray{T,N} where N},AbstractArray} where T
T4 = Tuple{typeof(convert),Type{AbstractArray{T,N}},AbstractArray{s57,N} where s57} where N where T

msp(T,S) = ccall(:jl_type_morespecific, Cint, (Any, Any), T, S) != 0
msp(T1, T2)
msp(T2, T3) && msp(T2, T4)
@assert msp(T1, T3)
@assert msp(T1, T4)

Find your own with:

using LightGraphs
Ts = map(x->x.sig, methods(convert))
g = SimpleDiGraph(length(Ts));
for ((i, T), (j, S)) in Iterators.product(enumerate(Ts), enumerate(Ts))
    if ccall(:jl_type_morespecific, Cint, (Any, Any), T, S) != 0
        add_edge!(g, i, j)
    end
end

for j in vertices(g)
    if !all(d->d in (0, 1, typemax(Int)), gdistances(g, j))
        error("Transitivity error at $(j)")
    end
end

Metadata

Metadata

Assignees

Labels

bugIndicates an unexpected problem or unintended behaviortypes and dispatchTypes, subtyping and method dispatch

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions