提交 cc7e706a 编写于 作者: C Charles Stoner 提交者: GitHub

Merge pull request #14755 from enkafan/bugfix/unboundlambda-unmatched-return-type-fix

Ensures cached lambda has matching return type for UnboundLambda binding
......@@ -427,10 +427,9 @@ private BoundLambda ReallyBind(NamedTypeSymbol delegateType)
MethodSymbol cacheKey = GetCacheKey(delegateType);
BoundLambda returnInferenceLambda;
if (_returnInferenceCache.TryGetValue(cacheKey, out returnInferenceLambda) && returnInferenceLambda.InferredFromSingleType)
if (_returnInferenceCache.TryGetValue(cacheKey, out returnInferenceLambda) && returnInferenceLambda.InferredFromSingleType && returnInferenceLambda.Symbol.ReturnType == returnType)
{
lambdaSymbol = returnInferenceLambda.Symbol;
Debug.Assert(lambdaSymbol.ReturnType == returnType);
Debug.Assert(lambdaSymbol.RefKind == refKind);
lambdaBodyBinder = returnInferenceLambda.Binder;
......
......@@ -485,6 +485,47 @@ public static void Main(string[] args)
.VerifyDiagnostics();
}
[Fact]
public void ConversionAppliedInLambdaForNonMatchingTypes()
{
var program = @"
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
var invoices = new List<Invoice>().AsQueryable();
var oneTimeCharges = new List<OneTimeCharge>().AsQueryable();
var otcCharges = invoices.Join(oneTimeCharges, inv => inv.InvoiceId, otc => otc.Invoice, (inv, otc) => inv.InvoiceId);
Console.Write('k');
}
}
public class OneTimeCharge
{
public int OneTimeChargeId { get; set; }
public int? Invoice { get; set; }
}
public class Invoice
{
public int InvoiceId { get; set; }
}
}
";
CompileAndVerify(
sources: new string[] { program, ExpressionTestLibrary },
additionalRefs: new[] { ExpressionAssemblyRef },
expectedOutput: @"k")
.VerifyDiagnostics();
}
[Fact]
public void Addition()
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册