diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs index 2b9042d77537a3e6add259c752d7415b25f014ae..da24d118b10786c980769b1c9dd3299e220a328a 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs @@ -1181,7 +1181,8 @@ private ImmutableArray 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); } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/OutVarTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/OutVarTests.cs index 8081100671193a49c96edb441743e1b5b79629f6..7bbb051dfddfc039274c63594790611fafe72a04 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/OutVarTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/OutVarTests.cs @@ -10925,9 +10925,6 @@ static bool TakeOutParam(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 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> 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 diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests_Scope.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests_Scope.cs index 81eebd80cc63d473819806db438bce81b23cdb68..34aa0b4566bcbffac4812ec16fd365ff9412a801 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests_Scope.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests_Scope.cs @@ -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),