From da02a145008ebd9ca39f090c46339b7e7b87037c Mon Sep 17 00:00:00 2001 From: Charles Stoner Date: Tue, 2 Jul 2019 10:28:28 -0700 Subject: [PATCH] Compile InvocationExpression target if necessary (dotnet/corefx#39101) Commit migrated from https://github.com/dotnet/corefx/commit/52a6a31678753e25ce9b6949d45ea85b215aed81 --- .../System/Linq/Expressions/Compiler/LambdaCompiler.Expressions.cs | 7 ++++++- src/libraries/System.Linq.Expressions/tests/Lambda/LambdaTests.cs | 1 - 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/LambdaCompiler.Expressions.cs b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/LambdaCompiler.Expressions.cs index 042140e..2024514 100644 --- a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/LambdaCompiler.Expressions.cs +++ b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/LambdaCompiler.Expressions.cs @@ -181,7 +181,12 @@ namespace System.Linq.Expressions.Compiler } expr = node.Expression; - Debug.Assert(!typeof(LambdaExpression).IsAssignableFrom(expr.Type)); + if (typeof(LambdaExpression).IsAssignableFrom(expr.Type)) + { + // if the invoke target is a lambda expression tree, first compile it into a delegate + expr = Expression.Call(expr, expr.Type.GetMethod("Compile", Array.Empty())); + } + EmitMethodCall(expr, expr.Type.GetInvokeMethod(), node, CompilationFlags.EmitAsNoTail | CompilationFlags.EmitExpressionStart); } diff --git a/src/libraries/System.Linq.Expressions/tests/Lambda/LambdaTests.cs b/src/libraries/System.Linq.Expressions/tests/Lambda/LambdaTests.cs index 915ce34..09719f7 100644 --- a/src/libraries/System.Linq.Expressions/tests/Lambda/LambdaTests.cs +++ b/src/libraries/System.Linq.Expressions/tests/Lambda/LambdaTests.cs @@ -56,7 +56,6 @@ namespace System.Linq.Expressions.Tests } [Theory, ClassData(typeof(CompilationTypes))] - [ActiveIssue(30471)] public void InvokeComputedLambda(bool useInterpreter) { ParameterExpression x = Expression.Parameter(typeof(int), "x"); -- 2.7.4