Skip to content

Commit 3d4652f

Browse files
committed
bugfix: implement two-arg show
1 parent e974f0e commit 3d4652f

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/FixFunctionArgument.jl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ module FixFunctionArgument
8585
end
8686
end
8787
function get_n(::Fix{N}) where {N}
88-
check_positive(N) - 1
88+
check_positive(N)
8989
end
9090
# Properties for compatility with `Base.Fix`
9191
const property_name_f = :f
@@ -104,7 +104,7 @@ module FixFunctionArgument
104104
end
105105
# Make `Fix` callable
106106
function (fix::Fix)(args::Vararg{Any, TupleLength}; kwargs...) where {TupleLength}
107-
n = get_n(fix)
107+
n = get_n(fix) - 1
108108
if length(args) < n
109109
throw_too_few_args()
110110
end
@@ -124,6 +124,18 @@ module FixFunctionArgument
124124
fixed_argument = fix.x
125125
callable(arg, fixed_argument; kwargs...)
126126
end
127+
function Base.show(io::IO, fix::Fix)
128+
n = get_n(fix)
129+
callable = fix.f
130+
fixed_argument = fix.x
131+
show(io, Fix{n})
132+
print(io, '(')
133+
show(io, callable)
134+
print(io, ',')
135+
print(io, ' ')
136+
show(io, fixed_argument)
137+
print(io, ')')
138+
end
127139
"""
128140
Fix1
129141

test/runtests.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ using Test
3535
@test_throws Exception fixed.z
3636
end
3737
end
38+
@testset "two-argument `show` roundtripping" begin
39+
for N (1, 2, 3, 999)
40+
for x (Fix{N}(convert, Float32), Fix{N}(Int, 7))
41+
@test x === (eval Meta.parse repr)(x)
42+
end
43+
let x = Fix{N}(Int, big(7))
44+
@test repr(x) == (repr eval Meta.parse repr)(x)
45+
end
46+
end
47+
end
3848
end
3949

4050
using Aqua: Aqua

0 commit comments

Comments
 (0)