提交 402e3eb0 编写于 作者: A AlekseyTs

Add a test for https://devdiv.visualstudio.com/DevDiv/_workitems?id=278481.

Also added some checks that should help to figure out how to reproduce the crash.
上级 92f0324c
......@@ -487,6 +487,21 @@ private BoundLambda ReallyBind(NamedTypeSymbol delegateType)
SourceMemberMethodSymbol.ReportAsyncParameterErrors(lambdaSymbol.Parameters, diagnostics, lambdaSymbol.Locations[0]);
}
// This is an attempt to get a repro for https://devdiv.visualstudio.com/DevDiv/_workitems?id=278481
if ((object)returnType != null && returnType.SpecialType != SpecialType.System_Void &&
!block.HasErrors && !diagnostics.HasAnyResolvedErrors() && block.Statements.Length > 0)
{
BoundStatement first = block.Statements[0];
if (first.Kind == BoundKind.ReturnStatement)
{
var returnStmt = (BoundReturnStatement)first;
if (returnStmt.ExpressionOpt != null && (object)returnStmt.ExpressionOpt.Type == null)
{
throw ExceptionUtilities.Unreachable;
}
}
}
var result = new BoundLambda(_unboundLambda.Syntax, block, diagnostics.ToReadOnlyAndFree(), lambdaBodyBinder, delegateType, inferReturnType: false)
{ WasCompilerGenerated = _unboundLambda.WasCompilerGenerated };
......
......@@ -956,6 +956,12 @@ public BoundExpression Null(TypeSymbol type)
public BoundTypeExpression Type(TypeSymbol type)
{
// This is an attempt to get a repro for https://devdiv.visualstudio.com/DevDiv/_workitems?id=278481
if ((object)type == null)
{
throw ExceptionUtilities.Unreachable;
}
return new BoundTypeExpression(Syntax, null, type) { WasCompilerGenerated = true };
}
......
......@@ -2290,5 +2290,70 @@ public static class C
var comp = CreateCompilationWithMscorlib(source);
CompileAndVerify(comp);
}
[Fact, WorkItem(278481, "https://devdiv.visualstudio.com/DevDiv/_workitems?id=278481")]
public void LambdaReturningNull()
{
var src = @"
public static class ExtensionMethods
{
public static System.Linq.IQueryable<TResult> LeftOuterJoin<TOuter, TInner, TKey, TResult>(
this System.Linq.IQueryable<TOuter> outerValues,
System.Linq.IQueryable<TInner> innerValues,
System.Linq.Expressions.Expression<System.Func<TOuter, TKey>> outerKeySelector,
System.Linq.Expressions.Expression<System.Func<TInner, TKey>> innerKeySelector,
System.Linq.Expressions.Expression<System.Func<TOuter, TInner, TResult>> fullResultSelector,
System.Linq.Expressions.Expression<System.Func<TOuter, TResult>> partialResultSelector,
System.Collections.Generic.IEqualityComparer<TKey> comparer)
{ return null; }
public static System.Linq.IQueryable<TResult> LeftOuterJoin<TOuter, TInner, TKey, TResult>(
this System.Linq.IQueryable<TOuter> outerValues,
System.Linq.IQueryable<TInner> innerValues,
System.Linq.Expressions.Expression<System.Func<TOuter, TKey>> outerKeySelector,
System.Linq.Expressions.Expression<System.Func<TInner, TKey>> innerKeySelector,
System.Linq.Expressions.Expression<System.Func<TOuter, TInner, TResult>> fullResultSelector,
System.Linq.Expressions.Expression<System.Func<TOuter, TResult>> partialResultSelector)
{
System.Console.WriteLine(""1"");
return null;
}
public static System.Collections.Generic.IEnumerable<TResult> LeftOuterJoin<TOuter, TInner, TKey, TResult>(
this System.Collections.Generic.IEnumerable<TOuter> outerQueryable,
System.Collections.Generic.IEnumerable<TInner> innerQueryable,
System.Func<TOuter, TKey> outerKeySelector,
System.Func<TInner, TKey> innerKeySelector,
System.Func<TOuter, TInner, TResult> resultSelector)
{ return null; }
}
partial class C
{
public static void Main()
{
System.Linq.IQueryable<A> outerValue = null;
System.Linq.IQueryable<B> innerValues = null;
outerValue.LeftOuterJoin(innerValues,
co => co.id,
coa => coa.id,
(co, coa) => null,
co => co);
}
}
class A
{
public int id=2;
}
class B
{
public int id = 2;
}";
var comp = CreateCompilationWithMscorlibAndSystemCore(src, options: TestOptions.DebugExe);
CompileAndVerify(comp, expectedOutput: "1");
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册