Repository: dotnet/runtime
File: src/tests/Regressions/coreclr/GitHub_122933/test122933.cs (C#)

Code before:
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Linq;
using System.Reflection;
using Xunit;

// Small repro for ilasm/ildasm roundtrip issue with duplicated constraints
// This demonstrates the issue where constraints get duplicated during ilasm roundtrip
public interface IComp<TSelf>
    : IEq<TSelf>
        where TSelf : IComp<TSelf>?
{
}

public interface IEq<TSelf>
        where TSelf : IEq<TSelf>?
{
}

public class Test122933
{
    [Fact]
    public static int TestEntryPoint()
    {
        // Get the types
        Type ieqType = typeof(IEq<>);
        Type icompType = typeof(IComp<>);

        // Get the generic type parameter for IEq<TSelf>
        Type[] ieqTypeParams = ieqType.GetGenericArguments();
        if (ieqTypeParams.Length != 1)
        {
            Console.WriteLine($"FAIL: IEq should have 1 generic parameter, but has {ieqTypeParams.Length}");
            return -1;
        }
        Type ieqTSelf = ieqTypeParams[0];

        // Get the constraints on IEq's TSelf parameter
        Type[] ieqConstraints = ieqTSelf.GetGenericParameterConstraints();
        
        // There should be exactly one constraint: IEq<TSelf>
        if (ieqConstraints.Length != 1)
        {
            Console.WriteLine($"FAIL: IEq<TSelf> should have 1 constraint, but has {ieqConstraints.Length}");
            return -1;
        }

        if (ieqConstraints[0].GetGenericTypeDefinition() != ieqType)
        {
            Console.WriteLine($"FAIL: IEq<TSelf> constraint should be IEq<>, but is {ieqConstraints[0].GetGenericTypeDefinition()}");

Review comment (suggestion):
@copilot Please delete all comments from this method. Comments like "Get the types` are not useful - they do not help with understanding the code

Code after:
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Reflection;
using Xunit;

// Validates that ilasm/ildasm roundtrip does not duplicate self-referential constraints

public interface IComp<TSelf>
    : IEq<TSelf>
        where TSelf : IComp<TSelf>?
{
}

public interface IEq<TSelf>
        where TSelf : IEq<TSelf>?
{
}

public class Test122933
{
    [Fact]
    public static int TestEntryPoint()
    {
        Type ieqType = typeof(IEq<>);
        Type icompType = typeof(IComp<>);

        Type[] ieqTypeParams = ieqType.GetGenericArguments();
        if (ieqTypeParams.Length != 1)
        {
            Console.WriteLine($"FAIL: IEq should have 1 generic parameter, but has {ieqTypeParams.Length}");
            return -1;
        }
        Type ieqTSelf = ieqTypeParams[0];

        Type[] ieqConstraints = ieqTSelf.GetGenericParameterConstraints();
        
        if (ieqConstraints.Length != 1)
        {
            Console.WriteLine($"FAIL: IEq<TSelf> should have 1 constraint, but has {ieqConstraints.Length}");
            return -1;
        }

        if (ieqConstraints[0].GetGenericTypeDefinition() != ieqType)
        {
            Console.WriteLine($"FAIL: IEq<TSelf> constraint should be IEq<>, but is {ieqConstraints[0].GetGenericTypeDefinition()}");
            return -1;
        }

        Type[] icompTypeParams = icompType.GetGenericArguments();
        if (icompTypeParams.Length != 1)