Skip to content

method sort order assertion #21710

@vtjnash

Description

@vtjnash

The following set of definitions should be sorted by number, but do not get sorted correctly:

f(::Vector) = 1
f(::AbstractVector) = 2
f(::Matrix) = 3
f(::AbstractMatrix) = 4
f(::Array) = 5 # this ends up between 1 and 2 instead!

Assertion failed: (!jl_subtype((jl_value_t*)sig, (jl_value_t*)type)), function check_ambiguous_visitor, file /Volumes/Lion/Users/jameson/Documents/julia/src/gf.c, line 1129.

This breaks the DataArrays package (which tries to add this set of methods to the round function)

Specifically, the bug is that the following result is wrong:

julia> args_morespecific(Tuple{Array}, Tuple{AbstractVector})
true

Or that the following result is wrong:

julia> args_morespecific(Tuple{Matrix}, Tuple{AbstractVector})
false

since because Matrix <: Array, more-specific(Matrix) should be higher than more-specific(Array)

more generally, I believe this means that the formal definition of more-specific is exactly:
more-specific(A, B) implies more-specific(C, D) for-all C <: A and D >: B

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