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

re-passing function keywords break type inference #22885

Closed
stevengj opened this issue Jul 20, 2017 · 2 comments
Closed

re-passing function keywords break type inference #22885

stevengj opened this issue Jul 20, 2017 · 2 comments
Labels
compiler:inference Type inference keyword arguments f(x; keyword=arguments)

Comments

@stevengj
Copy link
Member

stevengj commented Jul 20, 2017

Passing function keywords through a second function call seems to break type inference:

using StaticArrays, Base.Test
foo{n,T<:AbstractFloat}(f, a::SVector{n,T}, b::SVector{n,T}; norm=vecnorm) = f(norm(a + b) * n)
function foo(f, a::SVector{n,T}, b::SVector{n,S}; kws...) where {n,T<:Real,S<:Real}
    F = float(promote_type(T,S))
    return foo(f, SVector{n,F}(a), SVector{n,F}(b); kws...)
end

@inferred foo(abs, SVector(0.), SVector(1.))  # succeeds
@inferred foo(abs, SVector(0), SVector(1))    # FAILS!

If I delete the kws... in the second foo method then inference succeeds.

@stevengj stevengj added the compiler:inference Type inference label Jul 20, 2017
@JeffBezanson
Copy link
Member

JeffBezanson commented Jul 20, 2017

Yes, this is a pretty well-known pothole; see for example #9551 #21794 #21811.

@JeffBezanson JeffBezanson added the keyword arguments f(x; keyword=arguments) label Jul 20, 2017
stevengj added a commit to JuliaMath/HCubature.jl that referenced this issue Jul 20, 2017
@JeffBezanson
Copy link
Member

Closing as dup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:inference Type inference keyword arguments f(x; keyword=arguments)
Projects
None yet
Development

No branches or pull requests

2 participants