Skip to content

Interface stripping produces invalid inputs with covariant returns #2056

@MichalStrehovsky

Description

@MichalStrehovsky

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions