diff --git a/src/Compilers/CSharp/Portable/Lowering/SyntheticBoundNodeFactory.cs b/src/Compilers/CSharp/Portable/Lowering/SyntheticBoundNodeFactory.cs index 7c435662ea714733b9228cbfce3144dd6cd48a6d..67b6ffadff1b12fd56b07ed065236839301f62a6 100644 --- a/src/Compilers/CSharp/Portable/Lowering/SyntheticBoundNodeFactory.cs +++ b/src/Compilers/CSharp/Portable/Lowering/SyntheticBoundNodeFactory.cs @@ -64,7 +64,9 @@ public MethodSymbol CurrentMethod set { _currentMethod = value; - if ((object)value != null && value.MethodKind != MethodKind.AnonymousFunction) + if ((object)value != null && + value.MethodKind != MethodKind.AnonymousFunction && + value.MethodKind != MethodKind.LocalFunction) { _topLevelMethod = value; _currentType = value.ContainingType; diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_CallerInfoAttributes.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_CallerInfoAttributes.cs index e061d8f31362bef256a1a5d296428ffd77ba7713..03e525f61aefced86b64a05b24e671a6e9ec4ee2 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_CallerInfoAttributes.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_CallerInfoAttributes.cs @@ -1005,6 +1005,49 @@ public static void Main() CompileAndVerify(compilation, expectedOutput: expected); } + [Fact] + public void TestCallerMemberName_LocalFunction() + { + string source = @" +using System.Runtime.CompilerServices; +using System; + +class D +{ + public void LocalFunctionCaller() + { + void Local() + { + void LocalNested() => Test.Log(); + LocalNested(); + } + Local(); + } +} + +class Test +{ + public static int Log([CallerMemberName] string callerName = """") + { + Console.WriteLine(""name: "" + callerName); + return 1; + } + + public static void Main() + { + var d = new D(); + d.LocalFunctionCaller(); + } +}"; + + var expected = @" +name: LocalFunctionCaller +"; + + var compilation = CreateCompilationWithMscorlib45(source, references: new MetadataReference[] { SystemRef }, options: TestOptions.ReleaseExe); + CompileAndVerify(compilation, expectedOutput: expected); + } + [Fact] public void TestCallerMemberName_Operator() { diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenLocalFunctionTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenLocalFunctionTests.cs index 9d5d4f21348a623840ffc5ead4ca10c0e108e63d..a1f82d37727c84bea7a91add64d5afc54487c0b2 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenLocalFunctionTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenLocalFunctionTests.cs @@ -168,7 +168,7 @@ void LocalFuncName() Console.Write(' '); CallerMemberName(); "; - VerifyOutputInMain(source, "LocalFuncName Main", "System", "System.Runtime.CompilerServices"); + VerifyOutputInMain(source, "Main Main", "System", "System.Runtime.CompilerServices"); }