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_exists not working with TypeVar-parameterized types #9043

Closed
mauro3 opened this issue Nov 17, 2014 · 4 comments
Closed

method_exists not working with TypeVar-parameterized types #9043

mauro3 opened this issue Nov 17, 2014 · 4 comments

Comments

@mauro3
Copy link
Contributor

mauro3 commented Nov 17, 2014

Using TypeVars for non-parameterized types works with method_exists:

julia> I = TypeVar(:X, Integer)
X<:Integer

julia> Ii = TypeVar(:X, Int)
X<:Int64

julia> g{I<:Integer}(x::I) = x
g (generic function with 1 method)

julia> method_exists(g, (Integer,))
false

julia> method_exists(g, (Int,))
true

julia> method_exists(g, (I,))
false

julia> method_exists(g, (Ii,))
true

(Edit: Actually, shouldn't the second last return true as the method does exist for all <:Integer?)

But not for parameterized types:

julia> f{I<:Integer}(x::Array{I,1}) = x[5]
f (generic function with 1 method)

julia> method_exists(f, (Vector{Integer},))
true

julia> method_exists(f, (Vector{Int},))
true

julia> method_exists(f, (Vector{I},))
false

julia> method_exists(f, (Vector{Ii},))
false

I would have thought the latter two should return true.

@JeffBezanson
Copy link
Sponsor Member

Covered by #8974. Also please do not call TypeVar manually. It should probably not be exported, come to think of it.

@mauro3
Copy link
Contributor Author

mauro3 commented Nov 18, 2014

I'm using this over in Traits.jl, see mauro3/Traits.jl#2. I think, to store the signature of a parameterized function in a trait definition a TypeVar is needed as simple types cannot store that kind of subtype relationship. But that may change with #6984 & #8974.

@JeffBezanson
Copy link
Sponsor Member

It will need to change. I cannot figure out how to make the system work with unrestricted use of TypeVars. For example:

julia> T=TypeVar(:T)
T

julia> isa(T,Type{T})
true

julia> isa(Int,Type{T})
true

julia> Int==T
false

This breaks the rule that isa(x,Type{y}) <=> (x == y). In the future we will have isa(Int, @UnionAll T Type{T}), but not Type{T} by itself.

@mauro3
Copy link
Contributor Author

mauro3 commented Nov 19, 2014

Thanks for this clarification. I'm looking forward to #8974 sorting this all out!

mauro3 added a commit to mauro3/Traits.jl that referenced this issue Apr 10, 2015
These two bugs do not matter anymore as the new tests do not rely on method_exists:
method_exists_bug1 = false # see JuliaLang/julia#8959
method_exists_bug2 = false # see JuliaLang/julia#9043 and #2
mauro3 added a commit to mauro3/Traits.jl that referenced this issue Apr 14, 2015
These two bugs do not matter anymore as the new tests do not rely on method_exists:
method_exists_bug1 = false # see JuliaLang/julia#8959
method_exists_bug2 = false # see JuliaLang/julia#9043 and #2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants