Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interface stripping produces invalid inputs with covariant returns #2056

Open
MichalStrehovsky opened this issue May 26, 2021 · 1 comment
Open

Comments

@MichalStrehovsky
Copy link
Member

This is a flash from the past (#1235). When I fixed that issue, I remarked "It still makes me uneasy, but I can't come up with a scenario where it wouldn't work.".

I found a scenario where it doesn't work:

using System;
using System.Runtime.CompilerServices;

Base b = new Derived();
Console.WriteLine(b.GetFoo());

interface IFoo
{
}

class Foo : IFoo
{
}

class Base
{
    public virtual IFoo GetFoo() => throw new NotImplementedException();
}

class Derived : Base
{
    public override Foo GetFoo() => null;
}

Passing this program through illink produces

Unhandled exception. System.TypeLoadException: Return type in method 'Derived.GetFoo()' on type 'Derived' from assembly 'cons, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not compatible with base type method 'Base.GetFoo()'.
   at <Program>$.<Main>$(String[] args)
@MichalStrehovsky
Copy link
Member Author

I think a simple fix for this would be something along the lines of: "When marking a new member because it's an explicit override of another method but the return type doesn't match, do Annotations.MarkRelevantToVariantCasting on the overriden method's return type."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant