diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs index 0a84826cba8cde64d503048ea4f10b6933adeb1d..0dbaa3b2e88fd46844aaac08079d3476cc621161 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs @@ -2374,8 +2374,6 @@ internal GlobalExpressionVariable LookupDeclaredField(SyntaxNode node, string id hadError = true; } - - boundArgumentExpression = ToBadExpression(boundArgumentExpression); } result.Names.Add(nameColonSyntax.Name); @@ -2390,8 +2388,6 @@ internal GlobalExpressionVariable LookupDeclaredField(SyntaxNode node, string id hadError = true; } - boundArgumentExpression = ToBadExpression(boundArgumentExpression); - result.Names.Add(null); } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/BindingTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/BindingTests.cs index 7bfabc390a6397285b0b568284d47a84b2f71ee5..9dbb06f2531116b7169a8fba4f40442836cf4c84 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/BindingTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/BindingTests.cs @@ -2135,7 +2135,12 @@ static void M() }"; CreateCompilationWithMscorlib(source).VerifyDiagnostics( // (7,13): error CS1740: Named argument 'arg' cannot be specified multiple times - Diagnostic(ErrorCode.ERR_DuplicateNamedArgument, "arg").WithArguments("arg").WithLocation(7, 13)); + // arg: null); + Diagnostic(ErrorCode.ERR_DuplicateNamedArgument, "arg").WithArguments("arg").WithLocation(7, 13), + // (5,9): error CS1501: No overload for method 'M' takes 3 arguments + // M("", + Diagnostic(ErrorCode.ERR_BadArgCount, "M").WithArguments("M", "3").WithLocation(5, 9) + ); } [WorkItem(543820, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/543820")] diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NamedAndOptionalTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NamedAndOptionalTests.cs index f52d5b4bdc29f0afca7bbd6311d0b29fa8c79491..69c9be5cf20d72bd08b79ca8f87cf4f31b049635 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NamedAndOptionalTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NamedAndOptionalTests.cs @@ -174,7 +174,11 @@ public void M() Diagnostic(ErrorCode.ERR_BadNamedArgument, "optParam3").WithArguments("Foo", "optParam3").WithLocation(37, 15), // (39,30): error CS1738: Named argument specifications must appear after all fixed arguments have been specified // c.Foo(optArg1: 3333, 11111); - Diagnostic(ErrorCode.ERR_NamedArgumentSpecificationBeforeFixedArgument, "11111").WithLocation(39, 30)); + Diagnostic(ErrorCode.ERR_NamedArgumentSpecificationBeforeFixedArgument, "11111").WithLocation(39, 30), + // (39,15): error CS1739: The best overload for 'Foo' does not have a parameter named 'optArg1' + // c.Foo(optArg1: 3333, 11111); + Diagnostic(ErrorCode.ERR_BadNamedArgument, "optArg1").WithArguments("Foo", "optArg1").WithLocation(39, 15) + ); } [Fact] diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/OutVarTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/OutVarTests.cs index a88752df6362b34e54b506258f1dbef04ce91215..b159f3c7401a537387e9895c5cf8507cc6687245 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/OutVarTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/OutVarTests.cs @@ -18058,6 +18058,84 @@ static int Test1(out int x) Assert.Equal("System.Int32", model.GetTypeInfo(yRef).Type.ToTestDisplayString()); } + [Fact] + [WorkItem(15732, "https://github.com/dotnet/roslyn/issues/15732")] + public void LocalVariableTypeInferenceAndOutVar_06() + { + var text = @" +public class Cls +{ + public static void Main() + { + Test1(x: 1, out var y); + System.Console.WriteLine(y); + } + + static void Test1(int x, ref int y) + { + } +}"; + var compilation = CreateCompilationWithMscorlib(text, + options: TestOptions.ReleaseExe, + parseOptions: TestOptions.Regular); + + compilation.VerifyDiagnostics( + // (6,21): error CS1738: Named argument specifications must appear after all fixed arguments have been specified + // Test1(x: 1, out var y); + Diagnostic(ErrorCode.ERR_NamedArgumentSpecificationBeforeFixedArgument, "out var y").WithLocation(6, 21), + // (6,25): error CS1620: Argument 2 must be passed with the 'ref' keyword + // Test1(x: 1, out var y); + Diagnostic(ErrorCode.ERR_BadArgRef, "var y").WithArguments("2", "ref").WithLocation(6, 25) + ); + + var tree = compilation.SyntaxTrees.Single(); + var model = compilation.GetSemanticModel(tree); + + var yDecl = GetDeclaration(tree, "y"); + VerifyModelForOutVar(model, yDecl, GetReferences(tree, "y").ToArray()); + } + + [Fact] + [WorkItem(15732, "https://github.com/dotnet/roslyn/issues/15732")] + public void LocalVariableTypeInferenceAndOutVar_07() + { + var text = @" +public class Cls +{ + public static void Main() + { + int x = 0; + Test1(y: ref x, y: out var y); + System.Console.WriteLine(y); + } + + static void Test1(int x, ref int y) + { + } +}"; + var compilation = CreateCompilationWithMscorlib(text, + options: TestOptions.ReleaseExe, + parseOptions: TestOptions.Regular); + + compilation.VerifyDiagnostics( + // (7,25): error CS1740: Named argument 'y' cannot be specified multiple times + // Test1(y: ref x, y: out var y); + Diagnostic(ErrorCode.ERR_DuplicateNamedArgument, "y").WithArguments("y").WithLocation(7, 25), + // (7,9): error CS7036: There is no argument given that corresponds to the required formal parameter 'x' of 'Cls.Test1(int, ref int)' + // Test1(y: ref x, y: out var y); + Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "Test1").WithArguments("x", "Cls.Test1(int, ref int)").WithLocation(7, 9) + ); + + var tree = compilation.SyntaxTrees.Single(); + var model = compilation.GetSemanticModel(tree); + + var yDecl = GetDeclaration(tree, "y"); + var yRef = GetReferences(tree, "y").ToArray(); + Assert.Equal(3, yRef.Length); + Assert.Equal("System.Console.WriteLine(y)", yRef[2].Parent.Parent.Parent.ToString()); + VerifyModelForOutVar(model, yDecl, yRef[2]); + } + [Fact, WorkItem(13219, "https://github.com/dotnet/roslyn/issues/13219")] public void IndexingDynamic() { diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs index 198a1db4311f87ac600877d4dd31041700c429c9..feca821869ba6093ad2c742f1e2ffa0e861a6d43 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs @@ -15738,8 +15738,15 @@ public static int Main() public static void Test(int age , string Name) { } }"; - DiagnosticsUtils.VerifyErrorsAndGetCompilationWithMscorlib(text, - new ErrorDescription[] { new ErrorDescription { Code = 1740, Line = 6, Column = 29 } }); + var compilation = CSharpTestBase.CreateCompilationWithMscorlib(text); + compilation.VerifyDiagnostics( + // (6,29): error CS1740: Named argument 'Name' cannot be specified multiple times + // Test(Name: "5", Name: ""); + Diagnostic(ErrorCode.ERR_DuplicateNamedArgument, "Name").WithArguments("Name").WithLocation(6, 29), + // (6,13): error CS7036: There is no argument given that corresponds to the required formal parameter 'age' of 'C.Test(int, string)' + // Test(Name: "5", Name: ""); + Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "Test").WithArguments("age", "C.Test(int, string)").WithLocation(6, 13) + ); } [Fact]