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

VerificationException static virtual interface methods, and generic constraints #78865

Closed
vyacheslav-volkov opened this issue Nov 26, 2022 · 2 comments · Fixed by #89061
Closed
Assignees
Labels
area-TypeSystem-coreclr in-pr There is an active PR which will close this issue when it is merged
Milestone

Comments

@vyacheslav-volkov
Copy link

vyacheslav-volkov commented Nov 26, 2022

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

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Nov 26, 2022
@Joe4evr
Copy link
Contributor

Joe4evr commented Nov 26, 2022

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

@mangod9 mangod9 removed the untriaged New issue has not been triaged by the area owner label Mar 22, 2023
@mangod9 mangod9 added this to the 8.0.0 milestone Mar 22, 2023
@mangod9
Copy link
Member

mangod9 commented Mar 22, 2023

@davidwrighton @trylek as fyi.

@davidwrighton davidwrighton self-assigned this Jul 14, 2023
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jul 18, 2023
davidwrighton added a commit that referenced this issue Jul 19, 2023
… constraints (#89061)

- The major problem was the logic which incorrectly would instantiate the methods when it wasn't necessary
- As the number of flags to the implementation functions has grown very large, this change also includes logic converting them all to a single flags variable when passing them around

Fixes #73658
Fixes #78865
@ghost ghost locked as resolved and limited conversation to collaborators Sep 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-TypeSystem-coreclr in-pr There is an active PR which will close this issue when it is merged
Projects
None yet
4 participants