Repository navigation
Closed
Labels
Description
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.
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].
Activity
lambdageek commentedon Oct 17, 2024
@kg might be related to the covariant interfaces rewrite? (Although I didn't check how far back this goes)
kg commentedon Oct 17, 2024
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.
lambdageek commentedon Oct 17, 2024
It's not recent. Same behavior back to net6.0.
Here's what
abc.GetType().GetTypeInfo().GetInterfaces()returns on CoreCLR:And here's Mono:
medhatiwari commentedon Dec 5, 2024
Just an FYI: we are facing this issue here in efocre.pg while testing the driver on mono
Here is the issue
Fixes dotnet#108964 [Mono] ves_icall_RuntimeType_GetInterfaces genera…
dotnet#108964 [Mono] ves_icall_RuntimeType_GetInterfaces generates an…
dotnet#108964 [Mono] ves_icall_RuntimeType_GetInterfaces generates an…
dotnet#108964 [Mono] ves_icall_RuntimeType_GetInterfaces generates an…