未验证 提交 5b7c746c 编写于 作者: N Neal Gafter 提交者: GitHub

Do not run the spill sequence spiller on expression trees (#38435)

Fixes #37783
Fixes #38309
上级 244d3d42
......@@ -839,6 +839,12 @@ public override BoundNode VisitConditionalOperator(BoundConditionalOperator node
public override BoundNode VisitConversion(BoundConversion node)
{
if (node.ConversionKind == ConversionKind.AnonymousFunction && node.Type.IsExpressionTree())
{
// Expression trees do not contain any code that requires spilling.
return node;
}
BoundSpillSequenceBuilder builder = null;
var operand = VisitExpression(ref builder, node.Operand);
return UpdateExpression(
......
......@@ -3816,5 +3816,75 @@ public class Q
Diagnostic(ErrorCode.ERR_SpecialByRefInLambda, "{ P1: true }").WithArguments("S").WithLocation(9, 20)
);
}
[Fact]
[WorkItem(37783, "https://github.com/dotnet/roslyn/issues/37783")]
public void ExpressionLambdaWithObjectInitializer()
{
var source =
@"using System;
using System.Linq.Expressions;
using System.Threading.Tasks;
class Program
{
public static async Task Main()
{
int value = 42;
Console.WriteLine(await M(() => new Box<int>() { Value = value }));
}
static Task<int> M(Expression<Func<Box<int>>> e)
{
return Task.FromResult(e.Compile()().Value);
}
}
class Box<T>
{
public T Value;
}
";
CompileAndVerify(source, expectedOutput: "42", options: TestOptions.DebugExe);
CompileAndVerify(source, expectedOutput: "42", options: TestOptions.ReleaseExe);
}
[Fact]
[WorkItem(38309, "https://github.com/dotnet/roslyn/issues/38309")]
public void ExpressionLambdaWithUserDefinedControlFlow()
{
var source =
@"using System;
using System.Linq.Expressions;
using System.Threading.Tasks;
namespace RoslynFailFastReproduction
{
static class Program
{
static async Task Main(string[] args)
{
await MainAsync(args);
}
static async Task MainAsync(string[] args)
{
Expression<Func<AltBoolean, AltBoolean>> expr = x => x && x;
var result = await Task.FromResult(true);
Console.WriteLine(result);
}
class AltBoolean
{
public static AltBoolean operator &(AltBoolean x, AltBoolean y) => default;
public static bool operator true(AltBoolean x) => default;
public static bool operator false(AltBoolean x) => default;
}
}
}
";
CompileAndVerify(source, expectedOutput: "True", options: TestOptions.DebugExe);
CompileAndVerify(source, expectedOutput: "True", options: TestOptions.ReleaseExe);
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册