diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/LambdaSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/LambdaSymbol.cs index 0509cc7d969ae3d2ebc417583891ef45bdc99964..265a029ce5571df294233dcecf1bf1f0bfdbf09b 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/LambdaSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/LambdaSymbol.cs @@ -346,7 +346,7 @@ private static ParameterSymbol CopyParameter(ParameterSymbol parameter, MethodSy parameter.Type, parameter.Ordinal, parameter.RefKind, - string.Empty); // Make sure nothing binds to this. + GeneratedNames.LambdaCopyParameterName(parameter)); // Make sure nothing binds to this. } public sealed override bool Equals(object symbol) diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/GeneratedNames.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/GeneratedNames.cs index 6ebc7dda6b1f02d67e6dc398a9e1228d3afee147..889c280173d0d7266044abcafba1a54b16db796b 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/GeneratedNames.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/GeneratedNames.cs @@ -460,5 +460,10 @@ internal static string ReusableHoistedLocalFieldName(int number) Debug.Assert((char)GeneratedNameKind.ReusableHoistedLocalField == '7'); return "<>7__wrap" + StringExtensions.GetNumeral(number); } + + internal static string LambdaCopyParameterName(ParameterSymbol sourceParameter) + { + return "<" + sourceParameter.Name + ">"; + } } } diff --git a/src/Compilers/CSharp/Test/Semantic/FlowAnalysis/RegionAnalysisTests.cs b/src/Compilers/CSharp/Test/Semantic/FlowAnalysis/RegionAnalysisTests.cs index ebe20974aa4c34b17b920ee02edf92bd18ada5a9..f8be1209342d349230a3e72508d3c537c11389ce 100644 --- a/src/Compilers/CSharp/Test/Semantic/FlowAnalysis/RegionAnalysisTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/FlowAnalysis/RegionAnalysisTests.cs @@ -1593,7 +1593,7 @@ public static void Main() Assert.Null(GetSymbolNamesJoined(analysis.AlwaysAssigned)); Assert.Equal("p", GetSymbolNamesJoined(analysis.Captured)); Assert.Equal("i", GetSymbolNamesJoined(analysis.UnsafeAddressTaken)); - Assert.Equal("", GetSymbolNamesJoined(analysis.VariablesDeclared)); + Assert.Equal("

", GetSymbolNamesJoined(analysis.VariablesDeclared)); Assert.Equal("p", GetSymbolNamesJoined(analysis.DataFlowsIn)); Assert.Null(GetSymbolNamesJoined(analysis.DataFlowsOut)); @@ -1601,7 +1601,7 @@ public static void Main() Assert.Equal("p", GetSymbolNamesJoined(analysis.ReadInside)); Assert.Equal("i", GetSymbolNamesJoined(analysis.ReadOutside)); - Assert.Equal("", GetSymbolNamesJoined(analysis.WrittenInside)); + Assert.Equal("

", GetSymbolNamesJoined(analysis.WrittenInside)); Assert.Equal("i, p, d", GetSymbolNamesJoined(analysis.WrittenOutside)); } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/LambdaTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/LambdaTests.cs index d556466231a09bde9fac32fd284b4eb324c87c97..d17764d5649ea3aa1132af75a64724a5ab32bccd 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/LambdaTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/LambdaTests.cs @@ -1396,5 +1396,46 @@ public interface IColumn { } var compilation = CreateCompilationWithMscorlib(source, new[] { SystemCoreRef, CSharpRef }, options: TestOptions.ReleaseExe); CompileAndVerify(compilation, expectedOutput: "Select"); } + + [Fact, WorkItem(4527, "https://github.com/dotnet/roslyn/issues/4527")] + public void AnonymousMethodExpressionWithoutParameterList() + { + var source = +@" +using System; +using System.Threading.Tasks; + +namespace RoslynAsyncDelegate +{ + class Program + { + static EventHandler MyEvent; + + static void Main(string[] args) + { + MyEvent += async delegate { await Task.Delay(0); }; + } + } +} + +"; + var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugExe); + + var tree = compilation.SyntaxTrees[0]; + var model = compilation.GetSemanticModel(tree); + + var node1 = tree.GetRoot().DescendantNodes().Where(n => n.IsKind(SyntaxKind.AnonymousMethodExpression)).Single(); + + Assert.Equal("async delegate { await Task.Delay(0); }", node1.ToString()); + + Assert.Equal("void System.EventHandler.Invoke(System.Object sender, System.EventArgs e)", model.GetTypeInfo(node1).ConvertedType.GetMembers("Invoke").Single().ToTestDisplayString()); + + var lambdaParameters = ((MethodSymbol)(model.GetSymbolInfo(node1)).Symbol).Parameters; + + Assert.Equal("System.Object ", lambdaParameters[0].ToTestDisplayString()); + Assert.Equal("System.EventArgs ", lambdaParameters[1].ToTestDisplayString()); + + CompileAndVerify(compilation); + } } }