From 1e9c9b3fc6568f9a64782689f5d8c38670aa1a13 Mon Sep 17 00:00:00 2001 From: Paul Berg Date: Wed, 12 Jul 2023 18:42:01 +0200 Subject: [PATCH] ExEx: Track function calls in assignment lhs. --- src/analysis/ExpressionExplorer.jl | 9 +++++---- test/ExpressionExplorer.jl | 3 +++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/analysis/ExpressionExplorer.jl b/src/analysis/ExpressionExplorer.jl index 50b773d969..214dbf34e2 100644 --- a/src/analysis/ExpressionExplorer.jl +++ b/src/analysis/ExpressionExplorer.jl @@ -373,12 +373,13 @@ function explore_assignment!(ex::Expr, scopestate::ScopeState)::SymbolsState global_assignees = get_global_assignees(assignees, scopestate) # If we are _not_ assigning a global variable, then this symbol hides any global definition with that name - push!(scopestate.hiddenglobals, setdiff(assignees, global_assignees)...) + union!(scopestate.hiddenglobals, setdiff(assignees, global_assignees)) assigneesymstate = explore!(ex.args[1], scopestate) - push!(scopestate.hiddenglobals, global_assignees...) - push!(symstate.assignments, global_assignees...) - push!(symstate.references, setdiff(assigneesymstate.references, global_assignees)...) + union!(scopestate.hiddenglobals, global_assignees) + union!(symstate.assignments, global_assignees) + union!(symstate.references, setdiff(assigneesymstate.references, global_assignees)) + union!(symstate.funccalls, assigneesymstate.funccalls) filter!(!all_underscores, symstate.references) # Never record _ as a reference return symstate diff --git a/test/ExpressionExplorer.jl b/test/ExpressionExplorer.jl index 505b7470ea..2697f4a461 100644 --- a/test/ExpressionExplorer.jl +++ b/test/ExpressionExplorer.jl @@ -165,6 +165,9 @@ Some of these @test_broken lines are commented out to prevent printing to the te @test testee(:(x = let a = 1; a += b end), [:b], [:x], [:+], []) @test testee(:(_ = a + 1), [:a], [], [:+], []) @test testee(:(a = _ + 1), [], [:a], [:+], []) + + @test testee(:(f()[] = 1), [], [], [:f], []) + @test testee(:(x[f()] = 1), [:x], [], [:f], []) end @testset "Multiple assignments" begin # Note that using the shorthand syntax :(a = 1, b = 2) to create an expression