dotnet / dotnet/linker

Interface stripping produces invalid inputs with covariant returns

Open
#2,056 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
392
Forks
128
Avg merge
2d 10h
Merged PRs (30d)
2

Description

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:

```csharp
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 $.$(String[] args)
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.