Skip to content

Commit ba813ca

Browse files
committed
Uncomment tests using optional parameters in LINQ
Newer dotnet SDKs contain the fix for dotnet/csharplang#9246. This reverts commit 4f8ea72. Fixes #35547
1 parent 82d8bbf commit ba813ca

24 files changed

+1552
-1713
lines changed

src/EFCore/Query/Internal/ExpressionTreeFuncletizer.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

test/EFCore.Cosmos.FunctionalTests/Query/NorthwindAggregateOperatorsQueryCosmosTest.cs

Lines changed: 38 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,32 +1442,29 @@ WHERE ARRAY_CONTAINS(@ids, c["EmployeeID"])
14421442
""");
14431443
});
14441444

1445-
// TODO: The base implementations no longer compile since https://github.com/dotnet/runtime/pull/110197 (Contains overload added with
1446-
// optional parameter, not supported in expression trees). #35547 is tracking on the EF side.
1447-
//
1448-
// public override Task Contains_with_local_nullable_uint_array_closure(bool async)
1449-
// => Fixture.NoSyncTest(
1450-
// async, async a =>
1451-
// {
1452-
// await base.Contains_with_local_nullable_uint_array_closure(a);
1453-
//
1454-
// AssertSql(
1455-
// """
1456-
// @ids='[0,1]'
1457-
//
1458-
// SELECT VALUE c
1459-
// FROM root c
1460-
// WHERE ARRAY_CONTAINS(@ids, c["EmployeeID"])
1461-
// """,
1462-
// //
1463-
// """
1464-
// @ids='[0]'
1465-
//
1466-
// SELECT VALUE c
1467-
// FROM root c
1468-
// WHERE ARRAY_CONTAINS(@ids, c["EmployeeID"])
1469-
// """);
1470-
// });
1445+
public override Task Contains_with_local_nullable_uint_array_closure(bool async)
1446+
=> Fixture.NoSyncTest(
1447+
async, async a =>
1448+
{
1449+
await base.Contains_with_local_nullable_uint_array_closure(a);
1450+
1451+
AssertSql(
1452+
"""
1453+
@ids='[0,1]'
1454+
1455+
SELECT VALUE c
1456+
FROM root c
1457+
WHERE ARRAY_CONTAINS(@ids, c["EmployeeID"])
1458+
""",
1459+
//
1460+
"""
1461+
@ids='[0]'
1462+
1463+
SELECT VALUE c
1464+
FROM root c
1465+
WHERE ARRAY_CONTAINS(@ids, c["EmployeeID"])
1466+
""");
1467+
});
14711468

14721469
public override Task Contains_with_local_array_inline(bool async)
14731470
=> Fixture.NoSyncTest(
@@ -2007,25 +2004,21 @@ FROM root c
20072004
}
20082005
}
20092006

2010-
// TODO: The base implementations no longer compile since https://github.com/dotnet/runtime/pull/110197 (Contains overload added with
2011-
// optional parameter, not supported in expression trees). #35547 is tracking on the EF side.
2012-
//
2013-
//
2014-
// public override async Task Contains_with_local_tuple_array_closure(bool async)
2015-
// {
2016-
// // Contains over subquery. Issue #17246.
2017-
// await AssertTranslationFailed(() => base.Contains_with_local_tuple_array_closure(async));
2018-
//
2019-
// AssertSql();
2020-
// }
2021-
//
2022-
// public override async Task Contains_with_local_anonymous_type_array_closure(bool async)
2023-
// {
2024-
// // Contains over subquery. Issue #17246.
2025-
// await AssertTranslationFailed(() => base.Contains_with_local_anonymous_type_array_closure(async));
2026-
//
2027-
// AssertSql();
2028-
// }
2007+
public override async Task Contains_with_local_tuple_array_closure(bool async)
2008+
{
2009+
// Contains over subquery. Issue #17246.
2010+
await AssertTranslationFailed(() => base.Contains_with_local_tuple_array_closure(async));
2011+
2012+
AssertSql();
2013+
}
2014+
2015+
public override async Task Contains_with_local_anonymous_type_array_closure(bool async)
2016+
{
2017+
// Contains over subquery. Issue #17246.
2018+
await AssertTranslationFailed(() => base.Contains_with_local_anonymous_type_array_closure(async));
2019+
2020+
AssertSql();
2021+
}
20292022

20302023
public override async Task OfType_Select(bool async)
20312024
{

test/EFCore.Cosmos.FunctionalTests/Query/NorthwindWhereQueryCosmosTest.cs

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,16 +1627,13 @@ public override async Task Where_collection_navigation_ToArray_Count(bool async)
16271627
AssertSql();
16281628
}
16291629

1630-
// TODO: The base implementations no longer compile since https://github.com/dotnet/runtime/pull/110197 (Contains overload added with
1631-
// optional parameter, not supported in expression trees). #35547 is tracking on the EF side.
1632-
//
1633-
// public override async Task Where_collection_navigation_ToArray_Contains(bool async)
1634-
// {
1635-
// // Cosmos client evaluation. Issue #17246.
1636-
// await AssertTranslationFailed(() => base.Where_collection_navigation_ToArray_Contains(async));
1637-
//
1638-
// AssertSql();
1639-
// }
1630+
public override async Task Where_collection_navigation_ToArray_Contains(bool async)
1631+
{
1632+
// Cosmos client evaluation. Issue #17246.
1633+
await AssertTranslationFailed(() => base.Where_collection_navigation_ToArray_Contains(async));
1634+
1635+
AssertSql();
1636+
}
16401637

16411638
public override async Task Where_collection_navigation_AsEnumerable_Count(bool async)
16421639
{
@@ -1694,24 +1691,21 @@ FROM root c
16941691
""");
16951692
});
16961693

1697-
// TODO: The base implementations no longer compile since https://github.com/dotnet/runtime/pull/110197 (Contains overload added with
1698-
// optional parameter, not supported in expression trees). #35547 is tracking on the EF side.
1699-
//
1700-
// public override Task Where_array_of_object_contains_over_value_type(bool async)
1701-
// => Fixture.NoSyncTest(
1702-
// async, async a =>
1703-
// {
1704-
// await base.Where_array_of_object_contains_over_value_type(a);
1705-
//
1706-
// AssertSql(
1707-
// """
1708-
// @orderIds='[10248,10249]'
1709-
//
1710-
// SELECT VALUE c
1711-
// FROM root c
1712-
// WHERE ((c["$type"] = "Order") AND ARRAY_CONTAINS(@orderIds, c["OrderID"]))
1713-
// """);
1714-
// });
1694+
public override Task Where_array_of_object_contains_over_value_type(bool async)
1695+
=> Fixture.NoSyncTest(
1696+
async, async a =>
1697+
{
1698+
await base.Where_array_of_object_contains_over_value_type(a);
1699+
1700+
AssertSql(
1701+
"""
1702+
@orderIds='[10248,10249]'
1703+
1704+
SELECT VALUE c
1705+
FROM root c
1706+
WHERE ((c["$type"] = "Order") AND ARRAY_CONTAINS(@orderIds, c["OrderID"]))
1707+
""");
1708+
});
17151709

17161710
public override Task Filter_with_EF_Property_using_closure_for_property_name(bool async)
17171711
=> Fixture.NoSyncTest(

0 commit comments

Comments
 (0)