Skip to content

Commit 4d17411

Browse files
authored
In early exit, check signature for exact match (#17)
Fixes timholy/Revise.jl#318
1 parent 06ecb38 commit 4d17411

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/LoweredCodeUtils.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ function getcallee(stmt)
3737
error(stmt, " is not a call expression")
3838
end
3939

40-
ismethod(frame::Frame) = ismethod(pc_expr(frame))
40+
ismethod(frame::Frame) = ismethod(pc_expr(frame))
41+
ismethod3(frame::Frame) = ismethod3(pc_expr(frame))
4142
ismethod(stmt) = isexpr(stmt, :method)
4243
ismethod1(stmt) = isexpr(stmt, :method, 1)
4344
ismethod3(stmt) = isexpr(stmt, :method, 3)
@@ -356,7 +357,7 @@ function methoddef!(@nospecialize(recurse), signatures, frame::Frame, @nospecial
356357
end
357358
sigt, pc = signature(recurse, frame, stmt, pc)
358359
meth = whichtt(sigt)
359-
if meth === nothing && define
360+
if (meth === nothing || !(meth.sig <: sigt && sigt <: meth.sig)) && define
360361
step_expr!(recurse, frame, stmt, true)
361362
meth = whichtt(sigt)
362363
end

test/runtests.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,4 +250,14 @@ bodymethtest5(x, y=Dict(1=>2)) = 5
250250
@test startswith(String(bodymethod(first(methods(bodymethtest3))).name), "#")
251251
@test bodymethod(first(methods(bodymethtest4))).nargs == 3 # one extra for #self#
252252
@test bodymethod(first(methods(bodymethtest5))).nargs == 3
253+
254+
ex = :(typedsig(x) = 1)
255+
frame = JuliaInterpreter.prepare_thunk(Lowering, ex)
256+
methoddefs!(signatures, frame; define=true)
257+
ex = :(typedsig(x::Int) = 2)
258+
frame = JuliaInterpreter.prepare_thunk(Lowering, ex)
259+
JuliaInterpreter.next_until!(LoweredCodeUtils.ismethod3, frame, true)
260+
empty!(signatures)
261+
methoddefs!(signatures, frame; define=true)
262+
@test first(signatures).parameters[end] == Int
253263
end

0 commit comments

Comments
 (0)