Skip to content

Commit

Permalink
handle filters in generators (#839)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pangoraw authored Jan 13, 2021
1 parent ab7367a commit 6b6a1fd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/analysis/ExpressionExplorer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,9 @@ function explore!(ex::Expr, scopestate::ScopeState)::SymbolsState
elseif ex.head == :let || ex.head == :for || ex.head == :while
# Creates local scope
return explore_inner_scoped(ex, scopestate)
elseif ex.head == :filter
# In a filter, the assignment is the second expression, the condition the first
return mapfoldr(a -> explore!(a, scopestate), union!, ex.args, init=SymbolsState())
elseif ex.head == :generator
# Creates local scope

Expand Down
3 changes: 3 additions & 0 deletions test/ExpressionExplorer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ using Test
@test testee(:([sqrt(s) for s in 1:n]), [:n], [], [:sqrt, :(:)], [])
@test testee(:([sqrt(s + r) for s in 1:n, r in k]), [:n, :k], [], [:sqrt, :(:), :+], [])
@test testee(:([s + j + r + m for s in 1:3 for j in 4:5 for (r, l) in [(1, 2)]]), [:m], [], [:+, :(:)], [])
@test testee(:([a for a in b if a != 2]), [:b], [], [:(!=)], [])
@test testee(:([a for a in f() if g(a)]), [], [], [:f, :g], [])
@test testee(:([c(a) for a in f() if g(a)]), [], [], [:c, :f, :g], [])

@test testee(:([a for a in a]), [:a], [], [], [])
@test testee(:(for a in a; a; end), [:a], [], [], [])
Expand Down

0 comments on commit 6b6a1fd

Please sign in to comment.