Skip to content

VerificationException static virtual interface methods, and generic constraints #78865

Closed

Description

@vyacheslav-volkov

Description

I found code that throws a VerificationException for static virtual interface methods, and generic constraints, similar to this issue #73658 but without reflection.

Reproduction Steps

Run this code:

public interface ITestItem<T>
{
}

public interface IStaticInterfaceBase<T, in TRequest>
    where T : class
    where TRequest : IStaticInterfaceBase<T, TRequest>
{
    static abstract void TryInvoke<TItem>(TItem item, TRequest request) where TItem : ITestItem<T>;
}

public interface IStaticInterface<T, in TRequest> : IStaticInterfaceBase<T, TRequest>
    where T : class
    where TRequest : IStaticInterface<T, TRequest>
{
    static void IStaticInterfaceBase<T, TRequest>.TryInvoke<TItem>(TItem item, TRequest request)
    {
    }
}

public class Request : IStaticInterface<object, Request>
{
}

internal class Program
{
    public static void Invoke<T, TRequest>(TRequest request)
        where T : class
        where TRequest : IStaticInterfaceBase<T, TRequest> =>
        TRequest.TryInvoke((ITestItem<T>) null!, request);

    public static void Main(string[] args) => Invoke<object, Request>(new Request());
}

Expected behavior

The code will run without error.

Actual behavior

Unhandled exception. System.Security.VerificationException: Method StaticInterfaceBug.IStaticInterface`2[System.Object,StaticInterfaceBug.Request].StaticInterfaceBug.IStaticInterfaceBase<T,TRequest>.TryInvoke: type argument 'TItem' violates the constraint of type parameter 'TItem'.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Activity

  1. ghost added
    untriaged
    on Nov 26, 2022
  2. Joe4evr commented on Nov 26, 2022

    @Joe4evr
    Contributor

    @trylek Could this have the same underlying cause as the other issue?

  3. removed
    untriaged
    on Mar 22, 2023
  4. added this to the 8.0.0 milestone on Mar 22, 2023
  5. mangod9 commented on Mar 22, 2023

    @mangod9
    Member
  6. ghost added
    in-pr
    on Jul 18, 2023
  7. added a commit that references this issue on Jul 19, 2023
    d1adf81
  8. ghost locked as resolved and limited conversation to collaborators on Sep 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-TypeSystem-coreclrin-pr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions