Skip to content

[Mono] ves_icall_RuntimeType_GetInterfaces generates an extra Implemented Interface #108964

Closed

Description

@saitama951

The following test case fails on mono runtime

enum CarType{
            Coupe,
            Sedan
        }
        public static void Main(string []args)
        {
                var abc = new CarType[] {CarType.Coupe, CarType.Sedan};
                var def = new List<CarType> {CarType.Coupe, CarType.Sedan};
                Assert.Equal(abc, def);

//reproducible outside of xunit
                abc.AsNonStringTracker()
                
        }
       public static void AsNonStringTracker(this object value)
        {
                  IEnumerable enumerable = value as IEnumerable;
                  var iEnumerableOfT = enumerable.GetType().GetTypeInfo().ImplementedInterfaces.FirstOrDefault(i => i.IsConstructedGenericType && i.GetGenericTypeDefinition() == typeof(IEnumerable<>));
                 Console.WriteLine(iEnumerableOfT);
        }

result:

[ERROR] FATAL UNHANDLED EXCEPTION: Xunit.Sdk.EqualException: Assert.Equal() Failure: Collections differ
                         ↓ (pos 0, type System.Int32)
Expected: CarType[]     [0, 1]
Actual:   List<CarType> [Coupe, Sedan]
                         ↑ (pos 0, type Repro+CarType)
   at Xunit.Assert.Equal[IEnumerable`1](IEnumerable`1 expected, IEnumerable`1 actual, IEqualityComparer`1 comparer) in /home/sanjam/xunit/src/xunit.assert/Asserts/EqualityAsserts.cs:line 284
   at Xunit.Assert.Equal[CarType](IEnumerable`1 expected, IEnumerable`1 actual) in /home/sanjam/xunit/src/xunit.assert/Asserts/CollectionAsserts.cs:line 472
   at Repro.Main(String[] args) in /home/sanjam/repro/Program.cs:line 20

I believe this due to this
enumerable.GetType().GetTypeInfo().ImplementedInterfaces.FirstOrDefault(i => i.IsConstructedGenericType && i.GetGenericTypeDefinition() == typeof(IEnumerable<>)); generates 2 sequences and FirstOrDefault() picks the first one.

Reference:- https://github.com/xunit/assert.xunit/blob/main/Sdk/CollectionTrackerExtensions.cs#L81

System.Collections.Generic.IEnumerable`1[System.Int32]
System.Collections.Generic.IEnumerable`1[Repro+CarType]

The ImplementedInterfaces maps to mono call (ves_icall_RuntimeType_GetInterfaces) which generates this list.
I do see coreclr doesn't generate System.Collections.Generic.IEnumerable`1[System.Int32].

cc: @uweigand @akoeplinger @lambdageek @giritrivedi

Activity

  1. ghost added
    needs-area-label
    on Oct 17, 2024
  2. added
    untriaged
    on Oct 17, 2024
  3. added and removed
    needs-area-label
    on Oct 17, 2024
  4. lambdageek commented on Oct 17, 2024

    @lambdageek
    Member

    @kg might be related to the covariant interfaces rewrite? (Although I didn't check how far back this goes)

  5. kg commented on Oct 17, 2024

    @kg
    Contributor

    Could be related, yeah. I don't think "it enumerates as both int32 and the enumtype" is something I added but it's possible I made this quirk more visible.

  6. lambdageek commented on Oct 17, 2024

    @lambdageek
    Member

    It's not recent. Same behavior back to net6.0.

    Here's what abc.GetType().GetTypeInfo().GetInterfaces() returns on CoreCLR:

    System.ICloneable
    System.Collections.IList
    System.Collections.ICollection
    System.Collections.IEnumerable
    System.Collections.IStructuralComparable
    System.Collections.IStructuralEquatable
    System.Collections.Generic.IList`1[[CarType, a, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]
    System.Collections.Generic.ICollection`1[[CarType, a, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]
    System.Collections.Generic.IEnumerable`1[[CarType, a, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]
    System.Collections.Generic.IReadOnlyList`1[[CarType, a, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]
    System.Collections.Generic.IReadOnlyCollection`1[[CarType, a, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]
    

    And here's Mono:

    System.Collections.Generic.ICollection`1[[System.Int32, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]
    System.Collections.Generic.IList`1[[System.Int32, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]
    System.Collections.Generic.ICollection`1[[CarType, a, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]
    System.Collections.Generic.IList`1[[CarType, a, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]
    System.ICloneable
    System.Collections.IEnumerable
    System.Collections.Generic.IReadOnlyCollection`1[[System.Int32, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]
    System.Collections.Generic.IReadOnlyCollection`1[[CarType, a, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]
    System.Collections.Generic.IReadOnlyList`1[[System.Int32, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]
    System.Collections.Generic.IReadOnlyList`1[[CarType, a, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]
    System.Collections.IList
    System.Collections.IStructuralComparable
    System.Collections.IStructuralEquatable
    System.Collections.Generic.IEnumerable`1[[System.Int32, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]
    System.Collections.Generic.IEnumerable`1[[CarType, a, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]
    System.Collections.ICollection
    
  7. medhatiwari commented on Dec 5, 2024

    @medhatiwari
    Contributor

    Just an FYI: we are facing this issue here in efocre.pg while testing the driver on mono
    Here is the issue

  8. added 3 commits that reference this issue on Mar 19, 2025
    769a0ae
    0f60661
    a1a1678
  9. added
    in-pr
    on Mar 20, 2025
  10. added a commit that references this issue on Mar 20, 2025
  11. removed
    untriaged
    on Mar 20, 2025
  12. locked and limited conversation to collaborators on Apr 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-VM-meta-monoin-pr

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions