@@ -53,9 +53,10 @@ function signature(@nospecialize(recurse), frame::Frame, @nospecialize(stmt), pc
5353 stmt = pc_expr (frame, pc)
5454 end
5555 isa (stmt, Expr) || return nothing , pc
56+ mt = extract_method_table (frame, stmt; eval = false )
5657 sigsv = @lookup (frame, stmt. args[2 ]):: SimpleVector
5758 sigt = signature (sigsv)
58- return sigt, lastpc
59+ return mt => sigt, lastpc
5960end
6061signature (@nospecialize (recurse), frame:: Frame , pc) = signature (recurse, frame, pc_expr (frame, pc), pc)
6162signature (frame:: Frame , pc) = signature (finish_and_return!, frame, pc)
@@ -439,9 +440,9 @@ function get_running_name(@nospecialize(recurse), frame, pc, name, parentname)
439440 pctop -= 1
440441 stmt = pc_expr (frame, pctop)
441442 end # end fix
442- sigtparent, lastpcparent = signature (recurse, frame, pctop)
443+ (mt, sigtparent) , lastpcparent = signature (recurse, frame, pctop)
443444 sigtparent === nothing && return name, pc, lastpcparent
444- methparent = whichtt (sigtparent)
445+ methparent = whichtt (sigtparent, mt )
445446 methparent === nothing && return name, pc, lastpcparent # caller isn't defined, no correction is needed
446447 if isgen
447448 cname = GlobalRef (moduleof (frame), nameof (methparent. generator. gen))
@@ -507,6 +508,8 @@ function skip_until!(predicate, @nospecialize(recurse), frame)
507508 return pc
508509end
509510
511+ method_table (method:: Method ) = isdefined (method, :external_mt ) ? method. external_mt:: MethodTable : nothing
512+
510513"""
511514 ret = methoddef!(recurse, signatures, frame; define=true)
512515 ret = methoddef!(signatures, frame; define=true)
@@ -536,22 +539,22 @@ function methoddef!(@nospecialize(recurse), signatures, frame::Frame, @nospecial
536539 if ismethod3 (stmt)
537540 pc3 = pc
538541 arg1 = stmt. args[1 ]
539- sigt, pc = signature (recurse, frame, stmt, pc)
540- meth = whichtt (sigt)
542+ (mt, sigt) , pc = signature (recurse, frame, stmt, pc)
543+ meth = whichtt (sigt, mt )
541544 if isa (meth, Method) && (meth. sig <: sigt && sigt <: meth.sig )
542545 pc = define ? step_expr! (recurse, frame, stmt, true ) : next_or_nothing! (recurse, frame)
543546 elseif define
544547 pc = step_expr! (recurse, frame, stmt, true )
545- meth = whichtt (sigt)
548+ meth = whichtt (sigt, mt )
546549 end
547550 if isa (meth, Method) && (meth. sig <: sigt && sigt <: meth.sig )
548- push! (signatures, meth. sig)
551+ push! (signatures, mt => meth. sig)
549552 else
550553 if arg1 === false || arg1 === nothing
551554 # If it's anonymous and not defined, define it
552555 pc = step_expr! (recurse, frame, stmt, true )
553- meth = whichtt (sigt)
554- isa (meth, Method) && push! (signatures, meth. sig)
556+ meth = whichtt (sigt, mt )
557+ isa (meth, Method) && push! (signatures, mt => meth. sig)
555558 return pc, pc3
556559 else
557560 # guard against busted lookup, e.g., https://github.com/JuliaLang/julia/issues/31112
@@ -592,7 +595,7 @@ function methoddef!(@nospecialize(recurse), signatures, frame::Frame, @nospecial
592595 end
593596 found || return nothing
594597 while true # methods containing inner methods may need multiple trips through this loop
595- sigt, pc = signature (recurse, frame, stmt, pc)
598+ (mt, sigt) , pc = signature (recurse, frame, stmt, pc)
596599 stmt = pc_expr (frame, pc)
597600 while ! isexpr (stmt, :method , 3 )
598601 pc = next_or_nothing (recurse, frame, pc) # this should not check define, we've probably already done this once
@@ -607,8 +610,8 @@ function methoddef!(@nospecialize(recurse), signatures, frame::Frame, @nospecial
607610 # signature of the active method. So let's get the active signature.
608611 frame. pc = pc
609612 pc = define ? step_expr! (recurse, frame, stmt, true ) : next_or_nothing! (recurse, frame)
610- meth = whichtt (sigt)
611- isa (meth, Method) && push! (signatures, meth. sig) # inner methods are not visible
613+ meth = whichtt (sigt, mt )
614+ isa (meth, Method) && push! (signatures, mt => meth. sig) # inner methods are not visible
612615 name === name3 && return pc, pc3 # if this was an inner method we should keep going
613616 stmt = pc_expr (frame, pc) # there *should* be more statements in this frame
614617 end
0 commit comments