diff --git a/base/operators.jl b/base/operators.jl index bee2949e4918f..3936925bbbb1b 100644 --- a/base/operators.jl +++ b/base/operators.jl @@ -1170,13 +1170,13 @@ struct Fix{N,F,T} <: Function f::F x::T - function Fix{N}(f::F, x) where {N,F} + function Fix{N}(f::Union{F,Type{F}}, x) where {N,F} if !(N isa Int) throw(ArgumentError(LazyString("expected type parameter in `Fix` to be `Int`, but got `", N, "::", typeof(N), "`"))) elseif N < 1 throw(ArgumentError(LazyString("expected `N` in `Fix{N}` to be integer greater than 0, but got ", N))) end - new{N,_stable_typeof(f),_stable_typeof(x)}(f, x) + new{N,(f isa Type{F} ? Type{F} : F),_stable_typeof(x)}(f, x) end end diff --git a/test/functional.jl b/test/functional.jl index 9961b24fe8fa9..84c4098308ebd 100644 --- a/test/functional.jl +++ b/test/functional.jl @@ -352,5 +352,12 @@ end @test_throws ArgumentError("expected type parameter in `Fix` to be `Int`, but got `0.5::Float64`") Fix{0.5}(>, 1) @test_throws ArgumentError("expected type parameter in `Fix` to be `Int`, but got `1::UInt64`") Fix{UInt64(1)}(>, 1) end + @testset "Specialize to structs not in `Base`" begin + struct MyStruct + x::Int + end + f = Fix{1}(MyStruct, 1) + @test f isa Fix{1,Type{MyStruct},Int} + end end end