Skip to content

Commit 8848b96

Browse files
authored
Handle escaped assignee from macroexpand output (#29)
1 parent 1f21fe8 commit 8848b96

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/explore.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ function get_assignees(ex::Expr)::Vector{Symbol}
173173
# Handles splat assignments. e.g. _, y... = 1:5
174174
args = ex.args
175175
mapfoldl(get_assignees, union!, args; init=Symbol[])
176+
elseif Meta.isexpr(ex, :escape, 1)
177+
get_assignees(ex.args[1])
176178
else
177179
@warn "unknown use of `=`. Assignee is unrecognised." ex
178180
Symbol[]
@@ -1001,6 +1003,8 @@ function explore_funcdef!(ex::Expr, scopestate::ScopeState)::Tuple{FunctionName,
10011003

10021004
elseif ex.head === :(...)
10031005
return explore_funcdef!(ex.args[1], scopestate)
1006+
elseif ex.head === :escape
1007+
return explore_funcdef!(ex.args[1], scopestate)
10041008
else
10051009
return FunctionName(), explore!(ex, scopestate)
10061010
end

test/ExpressionExplorer.jl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,19 @@ end
134134
@test testee(:(abstract type a{T,S} end), [], [:a], [], [:a => ([], [], [], [])])
135135
@test testee(:(abstract type a{T} <: b end), [], [:a], [], [:a => ([:b], [], [], [])])
136136
@test testee(:(abstract type a{T} <: b{T} end), [], [:a], [], [:a => ([:b], [], [], [])])
137-
testee(macroexpand(Main, :(@enum a b c)), [], [], [], []; verbose=false)
137+
138+
# testee(macroexpand(Main, :(@enum NewType1 xx yy)), [], [], [], []; verbose=false) # test that it runs without error
139+
let result = ExpressionExplorer.compute_reactive_node(
140+
macroexpand(Main, :(@enum NewType2 xx yy))
141+
)
142+
143+
@test :NewType2 result.references
144+
@test :xx result.references
145+
146+
@test :NewType2 result.definitions result.funcdefs_without_signatures
147+
@test :xx result.definitions
148+
@test :yy result.definitions
149+
end
138150

139151
e = :(struct a end) # needs to be on its own line to create LineNumberNode
140152
@test testee(e, [], [:a], [], [:a => ([], [], [], [])])
@@ -346,6 +358,9 @@ end
346358
@test testee(:(function (A::MyType)(x; y=x) y + x end), [], [], [], [
347359
:MyType => ([], [], [:+], [])
348360
])
361+
@test testee(:(function $(esc(:g))() r = 2; r end), [], [], [], [
362+
:g => ([], [], [], [])
363+
])
349364
@test testee(:(f(x, y=a + 1) = x * y * z), [], [], [], [
350365
:f => ([:z, :a], [], [:*, :+], [])
351366
])

0 commit comments

Comments
 (0)