Skip to content

Commit

Permalink
fix: change in specialization from _stable_typeof
Browse files Browse the repository at this point in the history
  • Loading branch information
MilesCranmer committed Aug 1, 2024
1 parent ed64473 commit 4999c2f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions test/functional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4999c2f

Please sign in to comment.