@@ -17,16 +17,16 @@ public class AnotherObject
1717 public void LogInformation(string message, DateTime arg1) {}
1818 public void LogInformation2(string message, DateTime arg1) {}
1919 }
20-
20+
2121 public void LogInformation(string message, DateTime arg1) {}
2222 public void LogSomething(string message, DateTime arg1) {}
2323 public void AnotherMethod(string message, DateTime arg1) {}
24-
24+
2525 """ ;
2626 var sourceCode = $$ """
2727 const string message = "Event received at: {EventTime}";
2828 var eventTime = DateTime.Now;
29-
29+
3030 {{ LoggerName }} .LogInformation(message, eventTime);
3131
3232 AnotherMethod(message, eventTime);
@@ -48,8 +48,39 @@ public void AnotherMethod(string message, DateTime arg1) {}
4848 var methodSymbol = ( IMethodSymbol ) semanticModel . GetSymbolInfo ( c ) . Symbol ! ;
4949 return LogCallFilter . IsLoggerMethod ( methodSymbol ) ;
5050 } ) . ToArray ( ) ;
51-
51+
5252 invocationExpressions . Length . Should ( ) . Be ( 2 ) ;
5353 filteredInvocationExpressions . Length . Should ( ) . Be ( 1 ) ;
5454 }
55+
56+
57+ [ Fact ]
58+ public void Filter_WithInaccessibleClassAsParameter_ShouldExcludeLogCall ( )
59+ {
60+ const string additionalDeclarations = """
61+ public class A
62+ {
63+ private class B
64+ {
65+ public class C
66+ {
67+ public class D {}
68+ }
69+ }
70+ }
71+ """ ;
72+
73+ const string sourceCode = $$ """
74+ var parameter = new A.B.C.D();
75+ {{ LoggerName }} .LogInformation("B class is private, so {this} argument is inaccessible as well", parameter);
76+ """ ;
77+ var ( compilation , syntaxTree ) = CompileSourceCode ( sourceCode , additionalDeclarations ) ;
78+ var ( invocationExpressionSyntax , methodSymbol , _) = FindLoggerMethodInvocation ( compilation , syntaxTree ) ;
79+
80+ var isLogCallInvocation = LogCallFilter . IsLogCallInvocation ( invocationExpressionSyntax , CancellationToken . None ) ;
81+ var isLogCallMethod = LogCallFilter . IsLoggerMethod ( methodSymbol ) ;
82+
83+ isLogCallInvocation . Should ( ) . BeTrue ( ) ;
84+ isLogCallMethod . Should ( ) . BeFalse ( ) ;
85+ }
5586}
0 commit comments