diff --git a/src/Compilers/CSharp/Portable/FlowAnalysis/AbstractRegionDataFlowPass.cs b/src/Compilers/CSharp/Portable/FlowAnalysis/AbstractRegionDataFlowPass.cs index 68f6c828eff08..4e51e4c6715b4 100644 --- a/src/Compilers/CSharp/Portable/FlowAnalysis/AbstractRegionDataFlowPass.cs +++ b/src/Compilers/CSharp/Portable/FlowAnalysis/AbstractRegionDataFlowPass.cs @@ -49,6 +49,11 @@ public override BoundNode VisitLocalFunctionStatement(BoundLocalFunctionStatemen return base.VisitLocalFunctionStatement(node); } + public override BoundNode VisitNameOfOperator(BoundNameOfOperator node) + { + return node; + } + private void MakeSlots(ImmutableArray parameters) { // assign slots to the parameters diff --git a/src/Compilers/CSharp/Test/Semantic/FlowAnalysis/RegionAnalysisTests.cs b/src/Compilers/CSharp/Test/Semantic/FlowAnalysis/RegionAnalysisTests.cs index 6b6b577e777c0..6d30245cc40bc 100644 --- a/src/Compilers/CSharp/Test/Semantic/FlowAnalysis/RegionAnalysisTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/FlowAnalysis/RegionAnalysisTests.cs @@ -4774,6 +4774,60 @@ void N(System.Action x, System.Action y) { } Assert.Equal("this", GetSymbolNamesJoined(analysis.DefinitelyAssignedOnExit)); } + [Fact, WorkItem(53591, "https://github.com/dotnet/roslyn/issues/53591")] + public void TestNameOfInLambda() + { + var analysis = CompileAndAnalyzeDataFlowExpression(@" +class C +{ + void M() + { + Func x = /**/() => nameof(ClosureCreated)/**/; + } +}"); + + Assert.True(analysis.Succeeded); + Assert.Null(GetSymbolNamesJoined(analysis.Captured)); + Assert.Null(GetSymbolNamesJoined(analysis.CapturedInside)); + Assert.Null(GetSymbolNamesJoined(analysis.CapturedOutside)); + } + + [Fact, WorkItem(53591, "https://github.com/dotnet/roslyn/issues/53591")] + public void TestNameOfWithAssignmentInLambda() + { + var analysis = CompileAndAnalyzeDataFlowExpression(@" +class C +{ + void M() + { + Func x = /**/() => nameof(this = null)/**/; + } +}"); + + Assert.True(analysis.Succeeded); + Assert.Null(GetSymbolNamesJoined(analysis.Captured)); + Assert.Null(GetSymbolNamesJoined(analysis.CapturedInside)); + Assert.Null(GetSymbolNamesJoined(analysis.CapturedOutside)); + } + + [Fact, WorkItem(53591, "https://github.com/dotnet/roslyn/issues/53591")] + public void TestUnreachableThisInLambda() + { + var analysis = CompileAndAnalyzeDataFlowExpression(@" +class C +{ + void M() + { + Func x = /**/() => false ? this.ToString() : string.Empty/**/; + } +}"); + + Assert.True(analysis.Succeeded); + Assert.Equal("this", GetSymbolNamesJoined(analysis.Captured)); + Assert.Equal("this", GetSymbolNamesJoined(analysis.CapturedInside)); + Assert.Null(GetSymbolNamesJoined(analysis.CapturedOutside)); + } + [Fact] public void TestReturnFromLambda() { diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/OutVarTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/OutVarTests.cs index 28fa51a51b7ed..83a4312ec5bfd 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/OutVarTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/OutVarTests.cs @@ -35071,7 +35071,7 @@ public static void Main(string[] args) var decl = GetOutVarDeclaration(tree, name); var refs = GetReferences(tree, name).ToArray(); Assert.Equal(2, refs.Length); - VerifyModelForOutVar(model, decl, refs[0]); + VerifyModelForOutVar(model, decl, isDelegateCreation: false, isExecutableCode: false, isShadowed: false, references: refs[0]); VerifyNotInScope(model, refs[1]); var symbol = (ILocalSymbol)model.GetDeclaredSymbol(decl.Designation); Assert.Equal("System.Int32", symbol.Type.ToTestDisplayString());