Skip to content

Commit dc2c9e7

Browse files
committed
support 0-arg functions
1 parent 65d2451 commit dc2c9e7

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/RuntimeGeneratedFunctions.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct RuntimeGeneratedFunction{argnames, cache_tag, context_tag, id} <: Functio
4646
body::Expr
4747
function RuntimeGeneratedFunction(cache_tag, context_tag, ex)
4848
def = splitdef(ex)
49-
args, body = normalize_args(def[:args]), def[:body]
49+
args, body = normalize_args(get(def, :args, [])), def[:body]
5050
id = expr_to_id(body)
5151
cached_body = _cache_body(cache_tag, id, body)
5252
new{Tuple(args), cache_tag, context_tag, id}(cached_body)

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,14 @@ ex3 = :(function (_du::T,_u::Vector{E},_p::P,_t::Any) where {T<:Vector,E,P}
2727
nothing
2828
end)
2929

30+
31+
f0 = @RuntimeGeneratedFunction(()->42)
3032
f1 = @RuntimeGeneratedFunction(ex1)
3133
f2 = @RuntimeGeneratedFunction(ex2)
3234
f3 = @RuntimeGeneratedFunction(ex3)
3335

36+
@test f0() === 42
37+
3438
@test f1 isa Function
3539

3640
du = rand(2)

0 commit comments

Comments
 (0)