Skip to content

Commit e6679e1

Browse files
dgleichKristofferC
authored andcommitted
InteractiveUtils.jl: fixes issue where subtypes resolves bindings and causes deprecation warnings (#56306)
The current version of `subtypes` will throw deprecation errors even if no one is using the deprecated bindings. A similar bug was fixed in Aqua.jl - https://github.com/JuliaTesting/Aqua.jl/pull/89/files See discussion here: - JuliaIO/ImageMagick.jl#235 (for identifying the problem) - JuliaLang/Reexport.jl#42 (for pointing to the issue in Aqua.jl) - https://github.com/JuliaTesting/Aqua.jl/pull/89/files (for the fix in Aqua.jl) This adds the `isbindingresolved` test to the `subtypes` function to avoid throwing deprecation warnings. It also adds a test to check that this doesn't happen. --- On the current master branch (before the fix), the added test shows: ``` WARNING: using deprecated binding InternalModule.MyOldType in OuterModule. , use MyType instead. Subtypes and deprecations: Test Failed at /home/dgleich/devextern/julia/usr/share/julia/stdlib/v1.12/Test/src/Test.jl:932 Expression: isempty(stderr_content) Evaluated: isempty("WARNING: using deprecated binding InternalModule.MyOldType in OuterModule.\n, use MyType instead.\n") Test Summary: | Fail Total Time Subtypes and deprecations | 1 1 2.8s ERROR: LoadError: Some tests did not pass: 0 passed, 1 failed, 0 errored, 0 broken. in expression starting at /home/dgleich/devextern/julia/stdlib/InteractiveUtils/test/runtests.jl:841 ERROR: Package InteractiveUtils errored during testing ``` --- Using the results of this pull request: ``` @test_nowarn subtypes(Integer); ``` passes without error. The other tests pass too. (cherry picked from commit 20f933a)
1 parent 028858f commit e6679e1

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

stdlib/InteractiveUtils/src/InteractiveUtils.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ export apropos, edit, less, code_warntype, code_llvm, code_native, methodswith,
1111
import Base.Docs.apropos
1212

1313
using Base: unwrap_unionall, rewrap_unionall, isdeprecated, Bottom, show_unquoted, summarysize,
14-
signature_type, format_bytes
14+
signature_type, format_bytes, isbindingresolved
15+
1516
using Base.Libc
1617
using Markdown
1718

@@ -256,7 +257,7 @@ function _subtypes_in!(mods::Array, x::Type)
256257
m = pop!(mods)
257258
xt = xt::DataType
258259
for s in names(m, all = true)
259-
if isdefined(m, s) && !isdeprecated(m, s)
260+
if isbindingresolved(m, s) && !isdeprecated(m, s) && isdefined(m, s)
260261
t = getfield(m, s)
261262
dt = isa(t, UnionAll) ? unwrap_unionall(t) : t
262263
if isa(dt, DataType)

stdlib/InteractiveUtils/test/runtests.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,3 +721,22 @@ end
721721
end
722722

723723
@test Base.infer_effects(sin, (Int,)) == InteractiveUtils.@infer_effects sin(42)
724+
725+
# issue https://github.com/JuliaIO/ImageMagick.jl/issues/235
726+
module OuterModule
727+
module InternalModule
728+
struct MyType
729+
x::Int
730+
end
731+
732+
Base.@deprecate_binding MyOldType MyType
733+
734+
export MyType
735+
end
736+
using .InternalModule
737+
export MyType, MyOldType
738+
end # module
739+
@testset "Subtypes and deprecations" begin
740+
using .OuterModule
741+
@test_nowarn subtypes(Integer);
742+
end

0 commit comments

Comments
 (0)