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

Fix inference for fix(::Type, ...) #7

Merged
merged 2 commits into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Curry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ struct Fix{F, A, K} <: Function
k::K
end

Fix(::Type{T}, a, k) where {T} = Fix{Type{T}, typeof(a), typeof(k)}(T, a, k)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nice, I was not aware, that one can do this.


function (c::Fix)(args...; kw...)
c.f(interleave(c.a, args)...; c.k..., kw...)
end
Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ using Test
@inferred a1(1.0)
end

@testset "fix(::Type, ...)" begin
f = @inferred fix(CartesianIndex, nothing, Some(1))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This @inferred passes even without this change. Is it worth clarifying what it's trying to test?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its good to have this test. While this does not go wrong in master it is something that one can imagine going wrong. So this test makes future refactoring easier.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering what could go wrong that would make this test fail. I agree the test should stay.

@test @inferred(f(2)) === CartesianIndex(2, 1)
end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess if a type occurs in the fixed arguments, inference will fail? We could add a broken test for that (not sure whats the best way to spell out a broken @inferred though.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Positional arguments are inferrable after JuliaLang/julia#35980 (Julia >= 1.6) because the field type of Some(::Type{T}) is now Type{T}. If you want to fix it in earlier Julia, I think we can put the specialization for Some(::Type) in Compat.jl.

I think the only remaining problem is when a type is specified through a keyword argument.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's great that this works for args on 1.6. I think it's not worth fixing it for older versions, but it would be nice to have a broken test that reminds us about it. Especially the kw case, which is still open.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I added a broken test for keyword argumets in c63b9e7.

@testset "Fix.jl" begin

#=
Expand Down