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

Use of invoke with parametric types #22554

Closed
willtebbutt opened this issue Jun 26, 2017 · 3 comments · Fixed by #25495
Closed

Use of invoke with parametric types #22554

willtebbutt opened this issue Jun 26, 2017 · 3 comments · Fixed by #25495
Assignees
Labels
types and dispatch Types, subtyping and method dispatch

Comments

@willtebbutt
Copy link
Contributor

Suppose I have a function foo with methods whose signatures are

foo(x::Real, y::Real)
foo(x::Number, y::Number)

and I wish to invoke the 2nd method from within the 1st. In this case we could define the first method as follows to achieve the desired behaviour:

function foo(x::Real, y::Real)
    # Do stuff specific to Reals, whatever that happens to be.
    invoke(foo, Tuple{Number, Number}, x, y)
end

Now suppose we had instead defined methods with the following signatures:

foo(x::T, y::T) where T<:Real
foo(x::T, y::T) where T<:Number

The seemingly natural thing to do is to invoke using the appropriate UnionAll:

function foo(x::T, y::T) where T<:Real
    # Do stuff specific to pairs of Reals.
    invoke(foo, Tuple{V, V} where V<:Number, x, y)
end

However, this doesn't appear to work, yielding the following error:

ERROR: TypeError: foo: in invoke, expected Type, got Type{Tuple{V,V} where V<:Number}

Tested on both

Julia Version 0.6.0
Commit 903644385b (2017-06-19 13:05 UTC)

and

Julia Version 0.7.0-DEV.730
Commit c2c37ef8c5 (2017-06-26 07:41 UTC)

to make sure I hadn't missed a change.

@kshyatt kshyatt added the types and dispatch Types, subtyping and method dispatch label Jun 26, 2017
@JeffBezanson JeffBezanson self-assigned this Jun 27, 2017
@JeffBezanson
Copy link
Member

Yes, this capability is missing. There are still some code paths left that assume the type to look up is a direct Tuple type, but this can be fixed.

@jekbradbury
Copy link
Contributor

Is there a general way to ask something like "which method would have been invoked, given these arguments, if this method didn't exist?"

@willtebbutt
Copy link
Contributor Author

As it happens, I was trying to do exactly that when I ran into the above issue. I haven't found a solution that doesn't involve writing some code to examine the method table to determine which method is the next most specific, and then using invoke with whichever method is found's signature.

JeffBezanson added a commit that referenced this issue Jan 10, 2018
ScottPJones pushed a commit to ScottPJones/julia that referenced this issue Jan 11, 2018
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

Successfully merging a pull request may close this issue.

4 participants