Skip to content

Commit

Permalink
[metadata] Skip null vtable entires when checking covariant overrides
Browse files Browse the repository at this point in the history
When there are covariant return overrides, we check the vtable slot in every
parent class for signature compatability with the proposed override.

However if one of the ancestor classes is abstract, it could have an
abstract override for hte method:

    class Base {
      public virtual Base Method() => this;
    }
    public abstract Intermediate : Base {
      public override abstract Base Method();
    }
    public Leaf : Intermediate {
      public override Leaf Method() => this;
    }

In this case when we're checking that Leaf.Method is compatible with
the vtable slot in Intermediate, we will see a null method (since
Intermediate is abstract).  In such cases we can skip over the class
and continue with its parent.

Fixes
#76312
  • Loading branch information
lambdageek authored and github-actions committed Sep 28, 2022
1 parent 2ed5e04 commit c9bd7ae
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/mono/mono/metadata/class-setup-vtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -1656,6 +1656,10 @@ check_vtable_covariant_override_impls (MonoClass *klass, MonoMethod **vtable, in
break;
MonoMethod *prev_impl = cur_class->vtable[slot];

// if the current class re-abstracted the method, it may not be there.
if (!prev_impl)
continue;

if (prev_impl != last_checked_prev_override) {
/*
* the new impl should be subsumed by the prior one, ie this
Expand Down

0 comments on commit c9bd7ae

Please sign in to comment.