Skip to content

Commit 4236a69

Browse files
authored
Handle nested where statements (#126)
1 parent 4d504df commit 4236a69

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

src/utils.jl

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,25 @@ function is_func_expr(@nospecialize(ex), meth::Method)
9999
if !(isa(fname, Symbol) && is_gensym(fname)) && !isexpr(fname, :$)
100100
if fname === :Type && isexpr(ex.args[1], :where) && isexpr(callex.args[1], :(::)) && isexpr(callex.args[1].args[end], :curly)
101101
Tsym = callex.args[1].args[end].args[2]
102-
for wheretyp in ex.args[1].args[2:end]
103-
@assert isexpr(wheretyp, :(<:))
104-
if Tsym == wheretyp.args[1]
105-
fname = wheretyp.args[2]
106-
break
102+
whereex = ex.args[1]
103+
while true
104+
found = false
105+
for wheretyp in whereex.args[2:end]
106+
isexpr(wheretyp, :(<:)) || continue
107+
if Tsym == wheretyp.args[1]
108+
fname = wheretyp.args[2]
109+
found = true
110+
break
111+
end
107112
end
113+
found && break
114+
whereex = whereex.args[1]
108115
end
109116
end
110117
# match the function name
118+
if isexpr(fname, :curly)
119+
fname = fname.args[1]
120+
end
111121
fname === strip_gensym(meth.name) || return false
112122
end
113123
exargs = callex.args[2:end]

test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,12 @@ isdefined(Main, :Revise) ? Main.Revise.includet("script.jl") : include("script.j
273273
if !isdefined(Main, :Revise)
274274
@test definition(String, only(methods(wrongline))) === nothing
275275
end
276+
277+
# Nested `where`s
278+
m = @which Parametric{2}(5)
279+
src, line = definition(String, m)
280+
@test occursin("::Type{P}", src)
281+
@test line == 148
276282
end
277283

278284
@testset "With Revise" begin

test/script.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,7 @@ end
142142

143143
wrongline() = 1 # for use testing #124
144144
only(methods(wrongline)).line = 9999 # unclear how it happened in the wild, but this at least catches the problem
145+
146+
# Nested `where`s
147+
struct Parametric{N} end
148+
(::Type{P})(x::Int) where P<:Parametric{N} where N = P()

0 commit comments

Comments
 (0)