@@ -969,28 +969,32 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCall)
969969
970970 // .NET 10 made changes to overload resolution to prefer Span-based overloads when those exist ("first-class spans").
971971 // Unfortunately, the LINQ interpreter does not support ref structs, so we rewrite e.g. MemoryExtensions.Contains to
972- // Enumerable.Contains here. See https://github.com/dotnet/runtime/issues/109757.
972+ // Enumerable.Contains here. See https://github.com/dotnet/runtime/issues/109757, .
973973 if ( method . DeclaringType == typeof ( MemoryExtensions ) )
974974 {
975975 switch ( method . Name )
976976 {
977+ // Note that MemoryExtensions.Contains has an optional 3rd ComparisonType parameter; we only match when
978+ // it's null.
977979 case nameof ( MemoryExtensions . Contains )
978- when methodCall . Arguments is [ var arg0 , var arg1 ] && TryUnwrapSpanImplicitCast ( arg0 , out var unwrappedArg0 ) :
980+ when methodCall . Arguments is [ var spanArg , var valueArg , ..]
981+ && ( methodCall . Arguments . Count is 2 || methodCall . Arguments . Count is 3 && methodCall . Arguments [ 2 ] is ConstantExpression { Value : null } )
982+ && TryUnwrapSpanImplicitCast ( spanArg , out var unwrappedSpanArg ) :
979983 {
980984 return Visit (
981985 Call (
982986 EnumerableMethods . Contains . MakeGenericMethod ( methodCall . Method . GetGenericArguments ( ) [ 0 ] ) ,
983- unwrappedArg0 , arg1 ) ) ;
987+ unwrappedSpanArg , valueArg ) ) ;
984988 }
985989
986990 case nameof ( MemoryExtensions . SequenceEqual )
987- when methodCall . Arguments is [ var arg0 , var arg1 ]
988- && TryUnwrapSpanImplicitCast ( arg0 , out var unwrappedArg0 )
989- && TryUnwrapSpanImplicitCast ( arg1 , out var unwrappedArg1 ) :
991+ when methodCall . Arguments is [ var spanArg , var otherArg ]
992+ && TryUnwrapSpanImplicitCast ( spanArg , out var unwrappedSpanArg )
993+ && TryUnwrapSpanImplicitCast ( otherArg , out var unwrappedOtherArg ) :
990994 return Visit (
991995 Call (
992996 EnumerableMethods . SequenceEqual . MakeGenericMethod ( methodCall . Method . GetGenericArguments ( ) [ 0 ] ) ,
993- unwrappedArg0 , unwrappedArg1 ) ) ;
997+ unwrappedSpanArg , unwrappedOtherArg ) ) ;
994998 }
995999
9961000 static bool TryUnwrapSpanImplicitCast ( Expression expression , [ NotNullWhen ( true ) ] out Expression ? result )
0 commit comments