Skip to content

Unexpected method selected for dynamic dispatch on Julia 1.10.9 #57903

@Drvi

Description

@Drvi

The following code

struct NullableVector{T,V<:AbstractVector{T}} <: AbstractVector{Union{Nothing,T}}
    data::V
end
const NullableColumn{T} = NullableVector{T,Vector{T}}
const Column{T} = Union{Vector{T},NullableColumn{T}}

_maybe_push!(::Vector{T}) where {T} = sizeof(T)
_maybe_push!(column::NullableVector{T}) where {T} = _maybe_push!(column.data)
_maybe_push!(column::Column) = (println("Why we dispatch here? Input type is Vector type `$(typeof(column))`"); 0)

function _recycle!(columns::Vector{Column})
    for col in columns
        _maybe_push!(col)
    end
end

# Repro
cols = Column[Int[], UInt[], Float64[]]
_recycle!(cols)

Prints the following on Julia 1.10.9:

Why we dispatch here? Input type is Vector type `Vector{Int64}`
Why we dispatch here? Input type is Vector type `Vector{UInt64}`
Why we dispatch here? Input type is Vector type `Vector{Float64}`

I.e. we're dispatching to the _maybe_push!(column::Column) method, while the more specific _maybe_push!(::Vector{T}) method exists.

This does not reproduce if we @noinline the _maybe_push!(col) call site.
This issue doesn't reproduce on Julia 1.11.4 and 1.13.0-DEV.241, the expected method is selected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviorfixed on masterregression 1.10Regression in the 1.10 releasetypes 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