Skip to content

Commit

Permalink
fix #34286, regression in methods with empty tuple of types (#34291)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson authored Jan 7, 2020
1 parent 194a38b commit 8dc0d93
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 4 additions & 4 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -868,14 +868,14 @@ end
Return the method table for `f`.
If `types` is specified, return an array of methods whose types match.
If `module` is specified, return an array of methods defined in this module.
A list of modules can also be specified as an array or tuple.
If `module` is specified, return an array of methods defined in that module.
A list of modules can also be specified as an array.
!!! compat "Julia 1.4"
At least Julia 1.4 is required for specifying a module.
"""
function methods(@nospecialize(f), @nospecialize(t),
@nospecialize(mod::Union{Module,AbstractArray{Module},Tuple{Vararg{Module}},Nothing}=nothing))
@nospecialize(mod::Union{Module,AbstractArray{Module},Nothing}=nothing))
if mod isa Module
mod = (mod,)
end
Expand All @@ -900,7 +900,7 @@ function methods_including_ambiguous(@nospecialize(f), @nospecialize(t))
end

function methods(@nospecialize(f),
@nospecialize(mod::Union{Module,AbstractArray{Module},Tuple{Vararg{Module}},Nothing}=nothing))
@nospecialize(mod::Union{Module,AbstractArray{Module},Nothing}=nothing))
# return all matches
return methods(f, Tuple{Vararg{Any}}, mod)
end
Expand Down
10 changes: 6 additions & 4 deletions test/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,7 @@ end
module TestMod33403
f(x) = 1
f(x::Int) = 2
g() = 3

module Sub
import ..TestMod33403: f
Expand All @@ -905,18 +906,19 @@ end
end

@testset "methods with module" begin
using .TestMod33403: f
using .TestMod33403: f, g
@test length(methods(f)) == 3
@test length(methods(f, (Int,))) == 1

@test length(methods(f, TestMod33403)) == 2
@test length(methods(f, (TestMod33403,))) == 2
@test length(methods(f, [TestMod33403])) == 2
@test length(methods(f, (Int,), TestMod33403)) == 1
@test length(methods(f, (Int,), (TestMod33403,))) == 1
@test length(methods(f, (Int,), [TestMod33403])) == 1

@test length(methods(f, TestMod33403.Sub)) == 1
@test length(methods(f, (TestMod33403.Sub,))) == 1
@test length(methods(f, [TestMod33403.Sub])) == 1
@test length(methods(f, (Char,), TestMod33403.Sub)) == 1
@test length(methods(f, (Int,), TestMod33403.Sub)) == 0

@test length(methods(g, ())) == 1
end

0 comments on commit 8dc0d93

Please sign in to comment.