Skip to content

Method sorting with restricted/unrestricted type parameter (extracted from #6383) #23823

@iamed2

Description

@iamed2

A separate issue for @mbauman's #6383 (comment) which is distinct from the ambiguity problem.

julia> struct Foo{A<:Real} end

julia> f(x::Foo{A}) where A = 1
f (generic function with 1 method)

julia> f(x::Foo, y...) = 2
f (generic function with 2 methods)

julia> f(Foo{Int}())
2

The second method's 1-arg form appears (unless you're an Expert) as if it is less specific than the first. However, Foo is treated as Foo{T} where T<:Real, while the compiler puts a type bound of Any on A.

I think it would make sense if Foo{A} where A was treated as Foo{A} where A<:Real, at least in method definitions.

See also JuliaArrays/AxisArrays.jl#124 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    types 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