提交 787ebc2a 编写于 作者: C Charles Stoner

Ignore non-delegate types binding lambda arguments for error recovery

上级 4fa6e3fe
......@@ -1181,7 +1181,8 @@ private ImmutableArray<BoundExpression> BuildArgumentsForErrorRecovery(AnalyzedA
foreach (var parameterList in parameterListList)
{
var parameterType = GetCorrespondingParameterType(analyzedArguments, i, parameterList);
if (parameterType?.Kind == SymbolKind.NamedType)
if (parameterType?.Kind == SymbolKind.NamedType &&
(object)parameterType.GetDelegateType() != null)
{
var discarded = unboundArgument.Bind((NamedTypeSymbol)parameterType);
}
......
......@@ -10925,9 +10925,6 @@ static bool TakeOutParam<T>(T y, out T x)
// (115,15): error CS0103: The name 'u9' does not exist in the current context
// Dummy(u9);
Diagnostic(ErrorCode.ERR_NameNotInContext, "u9").WithArguments("u9").WithLocation(115, 15),
// (108,66): error CS0165: Use of unassigned local variable 'z9'
// group x > y9 && TakeOutParam(1, out var z9) && z9 ==
Diagnostic(ErrorCode.ERR_UseDefViolation, "z9").WithArguments("z9").WithLocation(108, 66),
// (121,24): error CS1931: The range variable 'y10' conflicts with a previous declaration of 'y10'
// from y10 in new[] { 1 }
Diagnostic(ErrorCode.ERR_QueryRangeVariableOverrides, "y10").WithArguments("y10").WithLocation(121, 24),
......@@ -28973,6 +28970,88 @@ public static void Main(int arg)
Assert.Equal("System.Int32", symbol.Type.ToTestDisplayString());
}
}
[Fact]
[WorkItem(17208, "https://github.com/dotnet/roslyn/issues/17208")]
public void ErrorRecoveryShouldIgnoreNonDelegates()
{
var source =
@"using System;
class C
{
static void Main()
{
G(x => x > 0 && F(out var y) && y > 0);
}
static bool F(out int i)
{
i = 0;
return true;
}
static void G(Func<int, bool> f, object o) { }
static void G(C c, object o) { }
}";
var comp = CreateCompilationWithMscorlibAndSystemCore(source);
comp.VerifyDiagnostics(
// (6,9): error CS1501: No overload for method 'G' takes 1 arguments
// G(x => x > 0 && F(out var y) && y > 0);
Diagnostic(ErrorCode.ERR_BadArgCount, "G").WithArguments("G", "1").WithLocation(6, 9));
}
[Fact]
[WorkItem(17208, "https://github.com/dotnet/roslyn/issues/17208")]
public void ErrorRecoveryShouldIgnoreNonDelegates_Expression()
{
var source =
@"using System;
using System.Linq.Expressions;
class C
{
static void Main()
{
G(x => x > 0 && F(out var y) && y > 0);
}
static bool F(out int i)
{
i = 0;
return true;
}
static void G(Expression<Func<int, bool>> f, object o) { }
static void G(C c, object o) { }
}";
var comp = CreateCompilationWithMscorlibAndSystemCore(source);
comp.VerifyDiagnostics(
// (7,9): error CS1501: No overload for method 'G' takes 1 arguments
// G(x => x > 0 && F(out var y) && y > 0);
Diagnostic(ErrorCode.ERR_BadArgCount, "G").WithArguments("G", "1").WithLocation(7, 9));
}
[Fact]
[WorkItem(17208, "https://github.com/dotnet/roslyn/issues/17208")]
public void ErrorRecoveryShouldIgnoreNonDelegates_Query()
{
var source =
@"using System.Linq;
class C
{
static void M()
{
var c = from x in new[] { 1, 2, 3 }
group x > 1 && F(out var y) && y == null
by x;
}
static bool F(out object o)
{
o = null;
return true;
}
}";
var comp = CreateCompilationWithMscorlibAndSystemCore(source);
comp.VerifyDiagnostics(
// (7,38): error CS8201: Out variable and pattern variable declarations are not allowed within a query clause.
// group x > 1 && F(out var y) && y == null
Diagnostic(ErrorCode.ERR_ExpressionVariableInQueryClause, "y").WithLocation(7, 38));
}
}
internal static class OutVarTestsExtensions
......@@ -1787,9 +1787,6 @@ void Test11()
// (115,15): error CS0103: The name 'u9' does not exist in the current context
// Dummy(u9);
Diagnostic(ErrorCode.ERR_NameNotInContext, "u9").WithArguments("u9").WithLocation(115, 15),
// (108,50): error CS0165: Use of unassigned local variable 'z9'
// group x > y9 && 1 is var z9 && z9 ==
Diagnostic(ErrorCode.ERR_UseDefViolation, "z9").WithArguments("z9").WithLocation(108, 50),
// (121,24): error CS1931: The range variable 'y10' conflicts with a previous declaration of 'y10'
// from y10 in new[] { 1 }
Diagnostic(ErrorCode.ERR_QueryRangeVariableOverrides, "y10").WithArguments("y10").WithLocation(121, 24),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册