Skip to content

Commit 8c02260

Browse files
authored
Support anonymous functions (#102)
Closes #80 Also makes a few CI fixes (custom Revise tests)
1 parent c3195cd commit 8c02260

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,15 @@ jobs:
4848
TERM="xterm" julia --project -i --code-coverage -e '
4949
using InteractiveUtils, REPL, Revise, Pkg
5050
Pkg.add("ColorTypes")
51-
# @async(Base.run_main_repl(true, true, false, true, false))
51+
@async(Base.run_main_repl(true, true, false, true, false))
5252
sleep(2)
5353
cd("test")
5454
include("runtests.jl")
55-
REPL.eval_user_input(:(exit()), Base.active_repl_backend)
55+
if Base.VERSION.major == 1 && Base.VERSION.minor >= 9
56+
REPL.eval_user_input(:(exit()), Base.active_repl_backend, Main)
57+
else
58+
REPL.eval_user_input(:(exit()), Base.active_repl_backend)
59+
end
5660
'
5761
- uses: julia-actions/julia-processcoverage@latest
5862
- uses: codecov/codecov-action@v3

src/utils.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ checkname(fname::Symbol, name::Symbol) = begin
2020
fname === name && return true
2121
startswith(string(name), string('#', fname, '#')) && return true
2222
string(name) == string(fname, "##kw") && return true
23+
match(r"^#\d+$", string(name)) !== nothing && return true # support `f = x -> 2x`
2324
return false
2425
end
2526
checkname(fname::Symbol, ::Nothing) = true

test/runtests.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ isdefined(Main, :Revise) ? Main.Revise.includet("script.jl") : include("script.j
163163
eval(ex)
164164
@test code_string(f_no_linenum, (Int,)) === nothing
165165

166+
# Issue #80
167+
m = only(methods(f80))
168+
src, line = definition(String, m)
169+
@test occursin("x^3", src)
170+
@test line == 52
171+
166172
# Invalidation-insulating methods used by Revise and perhaps others
167173
d = IdDict{Union{String,Symbol},Union{Function,Vector{Function}}}()
168174
CodeTracking.invoked_setindex!(d, sin, "sin")
@@ -286,7 +292,7 @@ struct Functor end
286292
@test body == "(::Functor)(x, y) = x+y"
287293
end
288294

289-
if v"1.6" <= VERSION < v"1.9"
295+
if v"1.6" <= VERSION < v"1.9-beta"
290296
@testset "kwfuncs" begin
291297
body, _ = CodeTracking.definition(String, @which fkw(; x=1))
292298
@test body == """

test/script.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,6 @@ end
4747
function fkw(; x=1)
4848
x
4949
end
50+
51+
# Issue #80
52+
f80 = x -> 2 * x^3 + 1

0 commit comments

Comments
 (0)