Skip to content

Commit 70b4052

Browse files
authored
improve function argument parsing (#130)
* fix issue 129 * strengthen test * add test * missing import * add test for #120 too * Revert "add test for #120 too" This reverts commit f204cd3.
1 parent 9abe158 commit 70b4052

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ExplicitImports"
22
uuid = "7d51a73a-1435-4ff3-83d9-f097790105c7"
33
authors = ["Eric P. Hanson"]
4-
version = "1.13"
4+
version = "1.13.1"
55

66
[deps]
77
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"

src/get_names_used.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,6 @@ end
196196
# check if `leaf` is a function argument (or kwarg), but not a default value etc,
197197
# which is part of a function definition (not just any function call)
198198
function is_non_anonymous_function_definition_arg(leaf)
199-
# a call who is a child of `function` or `=` is a function def
200-
# (I think!)
201199
if parents_match(leaf, (K"call",)) && call_is_func_def(parent(leaf))
202200
# We are a function arg if we're a child of `call` who is not the function name itself
203201
return child_index(leaf) != 1
@@ -241,7 +239,8 @@ function call_is_func_def(node)
241239
p === nothing && return false
242240
# note: macros only support full-form function definitions
243241
# (not inline)
244-
kind(p) in (K"function", K"macro") && return true
242+
# must be first child of function/macro to qualify
243+
kind(p) in (K"function", K"macro") && child_index(node) == 1 && return true
245244
return false
246245
end
247246

test/issue_129.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module Foo129
2+
foo() = 3
3+
h(f) = 4
4+
h(f, f2) = 4
5+
module Bar
6+
using ..Foo129: foo, h
7+
bar() = h(foo)
8+
9+
# we will test that the LHS foo is a function arg and the RHS ones are not
10+
bar2(x, foo) = h(foo, foo)
11+
end # Bar
12+
end # Foo129

test/runtests.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ include("test_explicit_imports.jl")
7777
include("main.jl")
7878
include("Test_Mod_Underscores.jl")
7979
include("module_alias.jl")
80+
include("issue_129.jl")
8081

8182
@testset "ExplicitImports" begin
8283
@testset "deprecations" begin
@@ -680,6 +681,12 @@ include("module_alias.jl")
680681
non_function_args = filter(!is_function_definition_arg, leaves)
681682
missed = filter(x -> get_val(x) === :a, non_function_args)
682683
@test isempty(missed)
684+
685+
# https://github.com/JuliaTesting/ExplicitImports.jl/issues/129
686+
df = DataFrame(get_names_used("issue_129.jl").per_usage_info)
687+
foos = subset(df, :name => ByRow(==(:foo)))
688+
@test only(subset(foos, :function_arg).location) == "issue_129.jl:10:9"
689+
check_no_stale_explicit_imports(Foo129, "issue_129.jl")
683690
end
684691

685692
@testset "has_ancestor" begin

0 commit comments

Comments
 (0)