Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
iamed2 opened this issue Sep 22, 2017 · 1 comment
Labels
types and dispatch Types, subtyping and method dispatch

Comments

@iamed2
Copy link
Contributor

iamed2 commented Sep 22, 2017

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)

@mbauman mbauman added the types and dispatch Types, subtyping and method dispatch label Sep 22, 2017
@JeffBezanson
Copy link
Member

The original issue isn't really specific to ambiguities; the underlying issue is exactly the same whether you get an ambiguity or an unexpected sort order.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

No branches or pull requests

3 participants