Skip to content

Regression in nightly: dispatch depends on order runtime calls, not signatures #49578

@odow

Description

@odow

JuMP/MathOptInterface is failing tests on nightly because of this regression.

Here's the latest nightly:

(base) oscar@Oscars-MBP ~ % /Applications/Julia-1.10.app/Contents/Resources/julia/bin/julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.10.0-DEV.1151 (2023-04-29)
 _/ |\__'_|_|_|\__'_|  |  Commit b4d15302517 (1 day old master)
|__/                   |

julia> struct Foo{T} end

julia> f = Foo{Int}()
Foo{Int64}()

julia> foo(::Type, ::Any) = nothing
foo (generic function with 1 method)

julia> foo(::Type{T}, f::T) where {T} = f
foo (generic function with 2 methods)

julia> foo(Foo{Int}, f)
Foo{Int64}()

julia> foo(Foo, f)         # <-- calls foo(::Type{T}, ::T)
Foo{Int64}()

julia> foo(Foo{String}, f)

julia> foo(Foo, f)         # <-- calls foo(::Type, ::Any)

The second call to foo(Foo, f) returns nothing instead of the desired Foo{Int64}().

Compare to v1.6.7

(base) oscar@Oscars-MBP MathOptInterface % julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.6.7 (2022-07-19)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> struct Foo{T} end

julia> f = Foo{Int}()
Foo{Int64}()

julia> foo(::Type, ::Any) = nothing
foo (generic function with 1 method)

julia> foo(::Type{T}, f::T) where {T} = f
foo (generic function with 2 methods)

julia> foo(Foo{Int}, f)
Foo{Int64}()

julia> foo(Foo, f)         # <-- calls foo(::Type{T}, ::T)
Foo{Int64}()

julia> foo(Foo{String}, f)

julia> foo(Foo, f)         # <-- calls foo(::Type{T}, ::T)
Foo{Int64}()

x-ref: jump-dev/MathOptInterface.jl#2159

I haven't tried bisecting. But based on our CI logs: https://github.com/jump-dev/MathOptInterface.jl/commits/master

Known good commit:

Julia Version 1.10.0-DEV.1069
Commit dcdac1e895f (2023-04-20 05:36 UTC)

Known bad commit:

Julia Version 1.10.0-DEV.1109
Commit c70e0fa552d (2023-04-24 22:47 UTC)

Diff dcdac1e...c70e0fa

Metadata

Metadata

Assignees

No one assigned

    Labels

    types and dispatchTypes, subtyping and method dispatch

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions