Skip to content

Commit ded8826

Browse files
authored
Don't scan for 3-arg method if there is none (#91)
This is the primary portion of the fix for timholy/Revise.jl#758
1 parent a14bd8e commit ded8826

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/signatures.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,19 @@ function methoddef!(@nospecialize(recurse), signatures, frame::Frame, @nospecial
506506
Base.invokelatest(error, "given invalid definition: ", stmt)
507507
end
508508
name = name::Symbol
509+
# Is there any 3-arg method definition with the same name? If not, avoid risk of executing code that
510+
# we shouldn't (fixes https://github.com/timholy/Revise.jl/issues/758)
511+
found = false
512+
for i = pc+1:length(framecode.src.code)
513+
newstmt = framecode.src.code[i]
514+
if ismethod3(newstmt)
515+
if ismethod_with_name(framecode.src, newstmt, string(name))
516+
found = true
517+
break
518+
end
519+
end
520+
end
521+
found || return nothing
509522
while true # methods containing inner methods may need multiple trips through this loop
510523
sigt, pc = signature(recurse, frame, stmt, pc)
511524
stmt = pc_expr(frame, pc)

src/utils.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ function ismethod_with_name(src, stmt, target::AbstractString; reentrant::Bool=f
9696
isdone = true
9797
end
9898
end
99+
# On Julia 1.6 we have to add escaping (CBinding makes function names like "(S)")
100+
target = escape_string(target, "()")
99101
return match(Regex("(^|#)$target(\$|#)"), string(name)) !== nothing
100102
end
101103

0 commit comments

Comments
 (0)