Skip to content

Commit

Permalink
Fix the order of DESTROY invocation.
Browse files Browse the repository at this point in the history
Make it correspond to S12-construction/destruction.t, i.e. from subclass
to parent classes; or, in other wosrds, reverse to (R)MRO.
  • Loading branch information
vrurg committed Dec 22, 2019
1 parent db65798 commit f2a4161
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/Perl6/Metamodel/Finalization.nqp
Expand Up @@ -3,28 +3,31 @@ role Perl6::Metamodel::Finalization {

method setup_finalization($obj) {
my @mro := self.mro($obj);
my int $i := nqp::elems(@mro);
my int $i := -1;
my $ocount := nqp::elems(@mro);
my @destroyers;
while --$i >= 0 {
while ++$i < $ocount {
my $class := @mro[$i];
my $classHOW := $class.HOW;
my $destroy := $classHOW.find_method($class, 'DESTROY', :no_fallback(1));
if !nqp::isnull($destroy) && $destroy {
nqp::push(@destroyers, $destroy);
}
if !self.lang-rev-before($obj, 'e')
&& nqp::can($classHOW, 'ins_roles')
&& nqp::can($classHOW, 'roles')
{
my @ins_roles := $classHOW.ins_roles($class, :with-submethods-only);
my $i := +@ins_roles;
while --$i >= 0 {
my $submeth := nqp::atkey(@ins_roles[$i].HOW.submethod_table(@ins_roles[$i]), 'DESTROY');
my $j := -1;
my $rcount := nqp::elems(@ins_roles);
while ++$j < $rcount {
my $r := @ins_roles[$j];
my $submeth := nqp::atkey(@ins_roles[$j].HOW.submethod_table(@ins_roles[$j]), 'DESTROY');
if !nqp::isnull($submeth) && $submeth {
nqp::push(@destroyers, $submeth);
}
}
}
my $destroy := $classHOW.find_method($class, 'DESTROY', :no_fallback(1));
if !nqp::isnull($destroy) && $destroy {
nqp::push(@destroyers, $destroy);
}
}
@!destroyers := @destroyers;
if @destroyers {
Expand Down

0 comments on commit f2a4161

Please sign in to comment.