Skip to content

Commit 87dff77

Browse files
authored
fix bug when include statement includes interpolation (#31)
1 parent 85bf7ef commit 87dff77

4 files changed

Lines changed: 67 additions & 55 deletions

File tree

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.4.0"
4+
version = "1.4.1"
55

66
[deps]
77
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"

src/parse_utilities.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,11 @@ function AbstractTrees.children(wrapper::SyntaxNodeWrapper)
6161
end
6262
if JuliaSyntax.kind(arg) == K"string"
6363
children = JuliaSyntax.children(arg)
64-
# string literals can only have one child (I think...)
64+
# if we have interpolation, there may be >1 child
65+
length(children) == 1 || @goto dynamic
6566
c = only(children)
67+
# if we have interpolation, this might not be a string
68+
kind(c) == K"String" || @goto dynamic
6669
# The children of a static include statement is the entire file being included
6770
new_file = joinpath(dirname(wrapper.file), c.val)
6871
if isfile(new_file)
@@ -80,6 +83,7 @@ function AbstractTrees.children(wrapper::SyntaxNodeWrapper)
8083
return [SkippedFile(location)]
8184
end
8285
else
86+
@label dynamic
8387
@warn "Dynamic `include` found at $location; not recursing"
8488
push!(wrapper.bad_locations, location)
8589
return [SkippedFile(location)]

test/DynMod.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,9 @@ get_file() = "hi.jl"
88

99
include(get_file())
1010

11+
include("$(get_file())")
12+
13+
hi = "hi"
14+
include("$(hi).jl")
15+
1116
end # DynMod

test/runtests.jl

Lines changed: 56 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -377,71 +377,74 @@ end
377377
@test contains(str, "has stale (unused) explicit imports for:")
378378

379379
@testset "Tainted modules" begin
380-
log = (:warn, r"Dynamic")
381-
382-
@test_logs log @test only_name_source(explicit_imports(DynMod, "DynMod.jl")) ==
383-
[DynMod => nothing, DynMod.Hidden => nothing]
384-
@test_logs log @test only_name_source(explicit_imports(DynMod, "DynMod.jl";
385-
strict=false)) ==
386-
[DynMod => [(; name=:print_explicit_imports,
387-
source=ExplicitImports)],
388-
# Wrong! Missing explicit export
389-
DynMod.Hidden => []]
390-
391-
@test_logs log @test explicit_imports_nonrecursive(DynMod, "DynMod.jl") === nothing
392-
393-
@test_logs log @test only_name_source(explicit_imports_nonrecursive(DynMod,
394-
"DynMod.jl";
395-
strict=false)) ==
396-
[(; name=:print_explicit_imports, source=ExplicitImports)]
397-
@test_logs log @test stale_explicit_imports(DynMod, "DynMod.jl") ==
398-
[DynMod => nothing,
399-
DynMod.Hidden => nothing]
400-
401-
@test_logs log @test stale_explicit_imports_nonrecursive(DynMod, "DynMod.jl") ===
402-
nothing
403-
404-
@test_logs log @test stale_explicit_imports(DynMod, "DynMod.jl"; strict=false) ==
405-
[DynMod => [],
406-
# Wrong! Missing stale explicit export
407-
DynMod.Hidden => []]
408-
409-
@test_logs log @test stale_explicit_imports_nonrecursive(DynMod, "DynMod.jl";
410-
strict=false) ==
411-
[]
412-
@test_logs log str = sprint(print_stale_explicit_imports, DynMod, "DynMod.jl")
380+
# 3 dynamic include statements
381+
l = (:warn, r"Dynamic")
382+
log = (l, l, l)
383+
384+
@test_logs log... @test only_name_source(explicit_imports(DynMod, "DynMod.jl")) ==
385+
[DynMod => nothing, DynMod.Hidden => nothing]
386+
@test_logs log... @test only_name_source(explicit_imports(DynMod, "DynMod.jl";
387+
strict=false)) ==
388+
[DynMod => [(; name=:print_explicit_imports,
389+
source=ExplicitImports)],
390+
# Wrong! Missing explicit export
391+
DynMod.Hidden => []]
392+
393+
@test_logs log... @test explicit_imports_nonrecursive(DynMod, "DynMod.jl") ===
394+
nothing
395+
396+
@test_logs log... @test only_name_source(explicit_imports_nonrecursive(DynMod,
397+
"DynMod.jl";
398+
strict=false)) ==
399+
[(; name=:print_explicit_imports, source=ExplicitImports)]
400+
@test_logs log... @test stale_explicit_imports(DynMod, "DynMod.jl") ==
401+
[DynMod => nothing,
402+
DynMod.Hidden => nothing]
403+
404+
@test_logs log... @test stale_explicit_imports_nonrecursive(DynMod, "DynMod.jl") ===
405+
nothing
406+
407+
@test_logs log... @test stale_explicit_imports(DynMod, "DynMod.jl"; strict=false) ==
408+
[DynMod => [],
409+
# Wrong! Missing stale explicit export
410+
DynMod.Hidden => []]
411+
412+
@test_logs log... @test stale_explicit_imports_nonrecursive(DynMod, "DynMod.jl";
413+
strict=false) ==
414+
[]
415+
@test_logs log... str = sprint(print_stale_explicit_imports, DynMod, "DynMod.jl")
413416
@test contains(str, "DynMod could not be accurately analyzed")
414417

415-
@test_logs log str = sprint(print_explicit_imports, DynMod, "DynMod.jl")
418+
@test_logs log... str = sprint(print_explicit_imports, DynMod, "DynMod.jl")
416419
@test contains(str, "DynMod could not be accurately analyzed")
417420

418-
@test_logs log @test check_no_implicit_imports(DynMod, "DynMod.jl";
419-
allow_unanalyzable=(DynMod,
420-
DynMod.Hidden)) ===
421-
nothing
421+
@test_logs log... @test check_no_implicit_imports(DynMod, "DynMod.jl";
422+
allow_unanalyzable=(DynMod,
423+
DynMod.Hidden)) ===
424+
nothing
422425

423426
# Ignore also works
424-
@test_logs log @test check_no_implicit_imports(DynMod, "DynMod.jl";
425-
allow_unanalyzable=(DynMod,),
426-
ignore=(DynMod.Hidden,)) ===
427-
nothing
427+
@test_logs log... @test check_no_implicit_imports(DynMod, "DynMod.jl";
428+
allow_unanalyzable=(DynMod,),
429+
ignore=(DynMod.Hidden,)) ===
430+
nothing
428431

429432
e = UnanalyzableModuleException
430-
@test_logs log @test_throws e check_no_implicit_imports(DynMod,
431-
"DynMod.jl")
433+
@test_logs log... @test_throws e check_no_implicit_imports(DynMod,
434+
"DynMod.jl")
432435

433436
# Missed `Hidden`
434-
@test_logs log @test_throws e check_no_implicit_imports(DynMod,
435-
"DynMod.jl";
436-
allow_unanalyzable=(DynMod,),)
437+
@test_logs log... @test_throws e check_no_implicit_imports(DynMod,
438+
"DynMod.jl";
439+
allow_unanalyzable=(DynMod,),)
437440

438-
@test_logs log @test check_no_stale_explicit_imports(DynMod, "DynMod.jl";
439-
allow_unanalyzable=(DynMod,
440-
DynMod.Hidden)) ===
441-
nothing
441+
@test_logs log... @test check_no_stale_explicit_imports(DynMod, "DynMod.jl";
442+
allow_unanalyzable=(DynMod,
443+
DynMod.Hidden)) ===
444+
nothing
442445

443-
@test_logs log @test_throws e check_no_stale_explicit_imports(DynMod,
444-
"DynMod.jl")
446+
@test_logs log... @test_throws e check_no_stale_explicit_imports(DynMod,
447+
"DynMod.jl")
445448

446449
str = sprint(Base.showerror, UnanalyzableModuleException(DynMod))
447450
@test contains(str, "was found to be unanalyzable")

0 commit comments

Comments
 (0)