Skip to content

Uncomment tests using optional parameters in LINQ #36057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/EFCore/Query/Internal/ExpressionTreeFuncletizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -969,28 +969,32 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCall)

// .NET 10 made changes to overload resolution to prefer Span-based overloads when those exist ("first-class spans").
// Unfortunately, the LINQ interpreter does not support ref structs, so we rewrite e.g. MemoryExtensions.Contains to
// Enumerable.Contains here. See https://github.com/dotnet/runtime/issues/109757.
// Enumerable.Contains here. See https://github.com/dotnet/runtime/issues/109757,.
if (method.DeclaringType == typeof(MemoryExtensions))
{
switch (method.Name)
{
// Note that MemoryExtensions.Contains has an optional 3rd ComparisonType parameter; we only match when
// it's null.
case nameof(MemoryExtensions.Contains)
when methodCall.Arguments is [var arg0, var arg1] && TryUnwrapSpanImplicitCast(arg0, out var unwrappedArg0):
when methodCall.Arguments is [var spanArg, var valueArg, ..]
&& (methodCall.Arguments.Count is 2 || methodCall.Arguments.Count is 3 && methodCall.Arguments[2] is ConstantExpression { Value: null })
&& TryUnwrapSpanImplicitCast(spanArg, out var unwrappedSpanArg):
{
return Visit(
Call(
EnumerableMethods.Contains.MakeGenericMethod(methodCall.Method.GetGenericArguments()[0]),
unwrappedArg0, arg1));
unwrappedSpanArg, valueArg));
}

case nameof(MemoryExtensions.SequenceEqual)
when methodCall.Arguments is [var arg0, var arg1]
&& TryUnwrapSpanImplicitCast(arg0, out var unwrappedArg0)
&& TryUnwrapSpanImplicitCast(arg1, out var unwrappedArg1):
when methodCall.Arguments is [var spanArg, var otherArg]
&& TryUnwrapSpanImplicitCast(spanArg, out var unwrappedSpanArg)
&& TryUnwrapSpanImplicitCast(otherArg, out var unwrappedOtherArg):
return Visit(
Call(
EnumerableMethods.SequenceEqual.MakeGenericMethod(methodCall.Method.GetGenericArguments()[0]),
unwrappedArg0, unwrappedArg1));
unwrappedSpanArg, unwrappedOtherArg));
}

static bool TryUnwrapSpanImplicitCast(Expression expression, [NotNullWhen(true)] out Expression? result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1442,32 +1442,29 @@ WHERE ARRAY_CONTAINS(@ids, c["EmployeeID"])
""");
});

// TODO: The base implementations no longer compile since https://github.com/dotnet/runtime/pull/110197 (Contains overload added with
// optional parameter, not supported in expression trees). #35547 is tracking on the EF side.
//
// public override Task Contains_with_local_nullable_uint_array_closure(bool async)
// => Fixture.NoSyncTest(
// async, async a =>
// {
// await base.Contains_with_local_nullable_uint_array_closure(a);
//
// AssertSql(
// """
// @ids='[0,1]'
//
// SELECT VALUE c
// FROM root c
// WHERE ARRAY_CONTAINS(@ids, c["EmployeeID"])
// """,
// //
// """
// @ids='[0]'
//
// SELECT VALUE c
// FROM root c
// WHERE ARRAY_CONTAINS(@ids, c["EmployeeID"])
// """);
// });
public override Task Contains_with_local_nullable_uint_array_closure(bool async)
=> Fixture.NoSyncTest(
async, async a =>
{
await base.Contains_with_local_nullable_uint_array_closure(a);

AssertSql(
"""
@ids='[0,1]'

SELECT VALUE c
FROM root c
WHERE ARRAY_CONTAINS(@ids, c["EmployeeID"])
""",
//
"""
@ids='[0]'

SELECT VALUE c
FROM root c
WHERE ARRAY_CONTAINS(@ids, c["EmployeeID"])
""");
});

public override Task Contains_with_local_array_inline(bool async)
=> Fixture.NoSyncTest(
Expand Down Expand Up @@ -2007,25 +2004,21 @@ FROM root c
}
}

// TODO: The base implementations no longer compile since https://github.com/dotnet/runtime/pull/110197 (Contains overload added with
// optional parameter, not supported in expression trees). #35547 is tracking on the EF side.
//
//
// public override async Task Contains_with_local_tuple_array_closure(bool async)
// {
// // Contains over subquery. Issue #17246.
// await AssertTranslationFailed(() => base.Contains_with_local_tuple_array_closure(async));
//
// AssertSql();
// }
//
// public override async Task Contains_with_local_anonymous_type_array_closure(bool async)
// {
// // Contains over subquery. Issue #17246.
// await AssertTranslationFailed(() => base.Contains_with_local_anonymous_type_array_closure(async));
//
// AssertSql();
// }
public override async Task Contains_with_local_tuple_array_closure(bool async)
{
// Contains over subquery. Issue #17246.
await AssertTranslationFailed(() => base.Contains_with_local_tuple_array_closure(async));

AssertSql();
}

public override async Task Contains_with_local_anonymous_type_array_closure(bool async)
{
// Contains over subquery. Issue #17246.
await AssertTranslationFailed(() => base.Contains_with_local_anonymous_type_array_closure(async));

AssertSql();
}

public override async Task OfType_Select(bool async)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1627,16 +1627,13 @@ public override async Task Where_collection_navigation_ToArray_Count(bool async)
AssertSql();
}

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

AssertSql();
}

public override async Task Where_collection_navigation_AsEnumerable_Count(bool async)
{
Expand Down Expand Up @@ -1694,24 +1691,21 @@ FROM root c
""");
});

// TODO: The base implementations no longer compile since https://github.com/dotnet/runtime/pull/110197 (Contains overload added with
// optional parameter, not supported in expression trees). #35547 is tracking on the EF side.
//
// public override Task Where_array_of_object_contains_over_value_type(bool async)
// => Fixture.NoSyncTest(
// async, async a =>
// {
// await base.Where_array_of_object_contains_over_value_type(a);
//
// AssertSql(
// """
// @orderIds='[10248,10249]'
//
// SELECT VALUE c
// FROM root c
// WHERE ((c["$type"] = "Order") AND ARRAY_CONTAINS(@orderIds, c["OrderID"]))
// """);
// });
public override Task Where_array_of_object_contains_over_value_type(bool async)
=> Fixture.NoSyncTest(
async, async a =>
{
await base.Where_array_of_object_contains_over_value_type(a);

AssertSql(
"""
@orderIds='[10248,10249]'

SELECT VALUE c
FROM root c
WHERE ((c["$type"] = "Order") AND ARRAY_CONTAINS(@orderIds, c["OrderID"]))
""");
});

public override Task Filter_with_EF_Property_using_closure_for_property_name(bool async)
=> Fixture.NoSyncTest(
Expand Down
Loading