- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.2k
Closed
Labels
area-NativeAOT-coreclrin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged
Milestone
Description
Description
when NativeAOT finds an covariant override it will pick that type as new return type and ignore further overrides that don't return the same type
tested with NativeAOT net7/8
Reproduction Steps
var impl = new Impl();
var subImpl = new SubImpl();
Console.WriteLine(impl.FromBase());
Console.WriteLine(impl.FromType());
Console.WriteLine(subImpl.FromBase());
Console.WriteLine(subImpl.FromType());
class Base
{
    public Base FromBase()
    {
        return FromType();
    }
    public virtual Base FromType()
    {
        return new Base();
    }
}
class Impl : Base
{
    public override Impl FromType()
    {
        return new Impl();
    }
}
class SubImpl : Impl
{
    // not called from FromBase()
    public override SubImpl FromType()
    {
        return new SubImpl();
    }
}Expected behavior
Impl
Impl
SubImpl
SubImpl
Actual behavior
Impl
Impl
Impl
SubImpl
Regression?
No response
Known Workarounds
don't use covariant return type
Configuration
.NET 8, Windows 10, x64, NativeAOT.
Other information
No response
Metadata
Metadata
Assignees
Labels
area-NativeAOT-coreclrin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged
Type
Projects
Status
No status