-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[metadata] Skip null vtable entries when checking covariant return ov…
…errides (#76323) * Add test for covariant reabstraction * [metadata] Skip null vtable entires when checking covariant overrides 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
1 parent
c8f9f29
commit 90d9034
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/tests/Loader/classloader/MethodImpl/CovariantReturns/UnitTest/OverrideReabstracted.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
|
||
|
||
namespace ReproMAUI6811; | ||
|
||
public static class Program | ||
{ | ||
public static int Main() | ||
{ | ||
Leaf l = new Leaf(); | ||
|
||
if (l.getI().ToString() != "Leaf") | ||
return 1; | ||
if (((Intermediate)l).getI().ToString() != "Leaf") | ||
return 2; | ||
if (((PseudoBase)l).getI().ToString() != "Leaf") | ||
return 3; | ||
if (((Base)l).getI().ToString() != "Leaf") | ||
return 4; | ||
return 100; | ||
} | ||
} | ||
|
||
public abstract class Base { | ||
public abstract I getI(); | ||
} | ||
|
||
public class PseudoBase : Base { | ||
public override I getI() => new C ("PseudoBase"); | ||
} | ||
|
||
public abstract class Intermediate : PseudoBase { | ||
public override abstract I getI(); | ||
} | ||
|
||
public class Leaf : Intermediate { | ||
public Leaf() {} | ||
public override C getI() { return new C ("Leaf"); } | ||
} | ||
|
||
public interface I {} | ||
|
||
public class C : I { | ||
private readonly string _repr; | ||
public C(string s) { _repr = s; } | ||
public override string ToString() => _repr; | ||
} | ||
|
||
|
8 changes: 8 additions & 0 deletions
8
...tests/Loader/classloader/MethodImpl/CovariantReturns/UnitTest/OverrideReabstracted.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildProjectName).cs" /> | ||
</ItemGroup> | ||
</Project> |