Skip to content

ILLink doesn't keep static default interface method for uninstantiated types #96854

@sbomer

Description

@sbomer

Similar to #96516, but not fixed by #96821. If the instance type is never instantiated, like below, ILLink doesn't keep the default interface implementation provided by IDerived:

Console.WriteLine(M<Instance>());

static int M<T>() where T : IBase {
    return T.Value;
}

interface IBase {
    static abstract int Value { get; }
}

interface IDerived : IBase {
    static int IBase.Value => 1;
}

class Instance : IDerived {
}

Trimmed output:

internal interface IBase
{
	static abstract int Value { get; }
}
internal class Instance : IBase
{
}

The trimmed app crashes with

Unhandled exception. System.TypeLoadException: Virtual static method 'get_Value' is not implemented on type 'Instance' from assembly 'trimmed-app, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
   at Program.<Main>$(String[])

Metadata

Metadata

Assignees

Labels

area-Tools-ILLink.NET linker development as well as trimming analyzers

Type

No type

Projects

Status

No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions