Skip to content

Commit

Permalink
Correct lambda evaluation in funcletizer
Browse files Browse the repository at this point in the history
Fixes #35152
  • Loading branch information
roji committed Nov 21, 2024
1 parent 89c8ad8 commit 445739a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/EFCore/Query/Internal/ExpressionTreeFuncletizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,9 @@ protected override Expression VisitLambda<T>(Expression<T> lambda)
}

lambda = lambda.Update(ProcessEvaluatableRoot(lambda.Body, ref _state), lambda.Parameters);
// TODO: For path tree calculation (NativeAOT), we need to set the state for CreateContainsEvaluatable, not NoEvaluatability,
// just like other node types. #35170.
_state = State.NoEvaluatability;
}

if (_state.ContainsEvaluatable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5317,6 +5317,12 @@ public override async Task Ternary_Null_StartsWith(bool async)
AssertSql();
}

// Unsupported ORDER BY clause. ORDER BY item expression could not be mapped to a document path.
public override Task Cast_to_object_over_parameter_directly_in_lambda(bool async)
=> Fixture.NoSyncTest(
async,
a => Assert.ThrowsAsync<CosmosException>(() => base.Cast_to_object_over_parameter_directly_in_lambda(a)));

private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5890,4 +5890,15 @@ public virtual Task Ternary_Null_StartsWith(bool async)
async,
ss => ss.Set<Order>().OrderBy(x => x.OrderID).Select(x => x == null ? null : x.OrderID + ""),
x => x.StartsWith("1"));

[ConditionalTheory] // #35152
[MemberData(nameof(IsAsyncData))]
public virtual Task Cast_to_object_over_parameter_directly_in_lambda(bool async)
{
var i = 8;

return AssertQuery(
async,
ss => ss.Set<Order>().OrderBy(o => (object)i).Select(o => o));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7516,6 +7516,17 @@ ORDER BY [o].[OrderID]
""");
}

public override async Task Cast_to_object_over_parameter_directly_in_lambda(bool async)
{
await base.Cast_to_object_over_parameter_directly_in_lambda(async);

AssertSql(
"""
SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate]
FROM [Orders] AS [o]
""");
}

private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);

Expand Down

0 comments on commit 445739a

Please sign in to comment.