diff --git a/src/utils.jl b/src/utils.jl index 44a5037..65e6210 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -99,15 +99,25 @@ function is_func_expr(@nospecialize(ex), meth::Method) if !(isa(fname, Symbol) && is_gensym(fname)) && !isexpr(fname, :$) if fname === :Type && isexpr(ex.args[1], :where) && isexpr(callex.args[1], :(::)) && isexpr(callex.args[1].args[end], :curly) Tsym = callex.args[1].args[end].args[2] - for wheretyp in ex.args[1].args[2:end] - @assert isexpr(wheretyp, :(<:)) - if Tsym == wheretyp.args[1] - fname = wheretyp.args[2] - break + whereex = ex.args[1] + while true + found = false + for wheretyp in whereex.args[2:end] + isexpr(wheretyp, :(<:)) || continue + if Tsym == wheretyp.args[1] + fname = wheretyp.args[2] + found = true + break + end end + found && break + whereex = whereex.args[1] end end # match the function name + if isexpr(fname, :curly) + fname = fname.args[1] + end fname === strip_gensym(meth.name) || return false end exargs = callex.args[2:end] diff --git a/test/runtests.jl b/test/runtests.jl index ccca744..72d6913 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -273,6 +273,12 @@ isdefined(Main, :Revise) ? Main.Revise.includet("script.jl") : include("script.j if !isdefined(Main, :Revise) @test definition(String, only(methods(wrongline))) === nothing end + + # Nested `where`s + m = @which Parametric{2}(5) + src, line = definition(String, m) + @test occursin("::Type{P}", src) + @test line == 148 end @testset "With Revise" begin diff --git a/test/script.jl b/test/script.jl index 61b4f23..1a4ea14 100644 --- a/test/script.jl +++ b/test/script.jl @@ -142,3 +142,7 @@ end wrongline() = 1 # for use testing #124 only(methods(wrongline)).line = 9999 # unclear how it happened in the wild, but this at least catches the problem + +# Nested `where`s +struct Parametric{N} end +(::Type{P})(x::Int) where P<:Parametric{N} where N = P()