From 81988c9ed8e56c97176038728ee9ba2ad8aaf39a Mon Sep 17 00:00:00 2001 From: TSR Berry <20988865+TSRBerry@users.noreply.github.com> Date: Tue, 16 Jan 2024 13:48:13 +0100 Subject: [PATCH] Add a new test and fix for logging statements in child blocks --- src/Ryujinx.Analyzers/CatchClauseAnalyzer.cs | 4 +-- .../CatchClauseAnalyzerTests.cs | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/Ryujinx.Analyzers/CatchClauseAnalyzer.cs b/src/Ryujinx.Analyzers/CatchClauseAnalyzer.cs index 2fbb209a7..f22be9dfc 100644 --- a/src/Ryujinx.Analyzers/CatchClauseAnalyzer.cs +++ b/src/Ryujinx.Analyzers/CatchClauseAnalyzer.cs @@ -146,9 +146,9 @@ namespace Ryujinx.Analyzers bool exceptionLogged = false; // Iterate through all expression statements - foreach (var statement in catchClauseSyntax.Block.Statements) + foreach (var blockNode in catchClauseSyntax.Block.DescendantNodes()) { - if (statement is not ExpressionStatementSyntax expressionStatement) + if (blockNode is not ExpressionStatementSyntax expressionStatement) { continue; } diff --git a/src/Ryujinx.Tests.Analyzers/CatchClauseAnalyzerTests.cs b/src/Ryujinx.Tests.Analyzers/CatchClauseAnalyzerTests.cs index 24e09af13..c5e4c8dab 100644 --- a/src/Ryujinx.Tests.Analyzers/CatchClauseAnalyzerTests.cs +++ b/src/Ryujinx.Tests.Analyzers/CatchClauseAnalyzerTests.cs @@ -214,6 +214,36 @@ public class MyClass } } } +"; + + await Verifier.VerifyAnalyzerAsync(text).ConfigureAwait(false); + } + + [Fact] + public async Task LogWithIdentifierInSubBlock_NoDiagnostic() + { + string text = _loggerText + @" +public class MyClass +{ + public void MyMethod9() + { + try + { + Console.WriteLine(""test""); + } + catch (Exception ex) + { + string testString = ""first time?""; + + if (1 == 1) + { + Ryujinx.Common.Logging.Logger.Info?.Print(Ryujinx.Common.Logging.LogClass.Application, $""test: {testString} Error: {ex.Message}""); + } + + Console.WriteLine(""Test""); + } + } +} "; await Verifier.VerifyAnalyzerAsync(text).ConfigureAwait(false);