Skip to content

Commit

Permalink
Merge pull request #71 from aplavin/expr
Browse files Browse the repository at this point in the history
fix constructorof(Expr)
  • Loading branch information
jw3126 authored Feb 23, 2023
2 parents 852910c + 16e8066 commit 19e8a6f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/nonstandard.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ constructorof(::Type{<:LinearAlgebra.Tridiagonal}) = tridiagonal_constructor
linrange_constructor(start, stop, len, lendiv) = LinRange(start, stop, len)

constructorof(::Type{<:LinRange}) = linrange_constructor

### Expr: args get splatted
# ::Expr annotation is to make it type-stable on Julia 1.3-
constructorof(::Type{<:Expr}) = (head, args) -> Expr(head, args...)::Expr
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ end
@inferred constructorof(typeof(lr1))(getfields(lr2)...)
end

@testset "Expr" begin
e = :(a + b)
@test e == @inferred constructorof(typeof(e))(getfields(e)...)
end
end

@testset "Anonymous function constructors" begin
Expand Down

0 comments on commit 19e8a6f

Please sign in to comment.