Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ExprTools"
uuid = "e2ba6199-217a-4e67-a87a-7c52f15ade04"
version = "0.1.11"
version = "0.1.12"

[compat]
julia = "1"
Expand Down
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ makedocs(;
authors="Curtis Vogt <curtis.vogt@gmail.com>",
repo="https://github.com/JuliaTesting/ExprTools.jl/blob/{commit}{path}#L{line}",
sitename="ExprTools.jl",
checkdocs=:exports,
format=Documenter.HTML(;
prettyurls=get(ENV, "CI", "false") == "true",
canonical="https://JuliaTesting.github.io/ExprTools.jl",
Expand Down
2 changes: 2 additions & 0 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ CurrentModule = ExprTools
splitdef
combinedef
signature
parameters
args_tuple_expr
```
8 changes: 5 additions & 3 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ julia> ex = :(
end
)
:(function Base.f(x::T, y::T) where T
#= none:2 =#
#= none:3 =#
x + y
end)

julia> def = splitdef(ex)
Dict{Symbol,Any} with 5 entries:
Dict{Symbol, Any} with 5 entries:
:args => Any[:(x::T), :(y::T)]
:body => quote…
:name => :(Base.f)
Expand All @@ -45,10 +46,11 @@ julia> eval(g_expr)
g (generic function with 1 method)

julia> g_method = first(methods(g))
g(x::T, y::T) where T in Main
g(x::T, y::T) where T
@ Main none:0

julia> signature(g_method)
Dict{Symbol,Any} with 3 entries:
Dict{Symbol, Any} with 3 entries:
:name => :g
:args => Expr[:(x::T), :(y::T)]
:whereparams => Any[:T]
Expand Down
9 changes: 8 additions & 1 deletion src/function.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,14 @@ function splitdef(ex::Expr; throw::Bool=true)

if length(ex.args) >= i
if ex.args[i] isa Expr && ex.args[i].head === :parameters
def[:kwargs] = ex.args[i].args
def[:kwargs] = Any[]
for arg in ex.args[i].args
if arg isa Expr && arg.head === :parameters

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
if arg isa Expr && arg.head === :parameters
if Meta.isexpr(arg, :parameters)

I am surprised that isn't used more in here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We should probably update this code to use Meta.isexpr. I'll leave it as I wrote it though so that everything is consistent. We can do a follow up PR for that change.

return invalid_def("more than one semicolon in argument list")
else
push!(def[:kwargs], arg)
end
end

if length(ex.args) > i
def[:args] = ex.args[(i + 1):end]
Expand Down
3 changes: 1 addition & 2 deletions test/function.jl
Original file line number Diff line number Diff line change
Expand Up @@ -875,8 +875,7 @@ function_form(short::Bool) = string(short ? "short" : "long", "-form")
@test_broken splitdef(:(a::Number::Int -> a); throws=false) === nothing

# Invalid argument block expression
ex = :((x; y; z) -> 0) # Note: inlining this strips LineNumberNodes from the block
@test any(arg -> arg isa LineNumberNode, ex.args[1].args)
ex = :((x; y; z) -> 0)
@test_splitdef_invalid ex
@test_splitdef_invalid Expr(:->, Expr(:block, :x, :y, :z), Expr(:block, 0))

Expand Down
Loading