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

Parameterized methods can shadow other method without error/warning #18892

Closed
mauro3 opened this issue Oct 12, 2016 · 4 comments
Closed

Parameterized methods can shadow other method without error/warning #18892

mauro3 opened this issue Oct 12, 2016 · 4 comments
Labels
domain:types and dispatch Types, subtyping and method dispatch
Milestone

Comments

@mauro3
Copy link
Contributor

mauro3 commented Oct 12, 2016

Parameterized methods are more specific than non-parameterized ones:

julia> g(x) = 1
g (generic function with 1 method)

julia> g{X}(x::X) = 2
g (generic function with 2 methods)

julia> g(4)
2

I don't think there is any way to call the first method of g.

Similarly for several arguments:

julia> h(x,y) = 1
h (generic function with 1 method)

julia> h{X}(x::X,y) = 2
h (generic function with 2 methods)

julia> h{X,Y}(x::X,y::Y) = 3
h (generic function with 3 methods)

julia> h{Y}(x,y::Y) = 4
h (generic function with 4 methods)

julia> h(4,5)
2

One solution is to consider above methods ambiguous and throw MethodError ... is ambiguous. on call. Another solution is to make those method definitions overwrite the previous one. Probably should be in sync with #8974.

X-ref: https://groups.google.com/d/msg/julia-users/-ldkZlbg76Q/pYRNT4eIBAAJ

@JeffBezanson
Copy link
Sponsor Member

Yes, #8974 will provide a definitive type equality test that will allow these method overwrites to happen.

@JeffBezanson
Copy link
Sponsor Member

closed by #18457

@vtjnash vtjnash reopened this Jan 16, 2017
@vtjnash
Copy link
Sponsor Member

vtjnash commented Jan 16, 2017

This is still an issue, since type-equal is not the same as sig-equal due to the extra parameters-must-match rule. That can cause us to incorrectly delete a method that may still be needed, or replace a method with one that is not equivalent (mostly resulting from Varargs).

@JeffBezanson
Copy link
Sponsor Member

Closing in favor of #21026, which is more specifically about that.

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

No branches or pull requests

3 participants