@@ -24,7 +24,8 @@ internal class GetXAnalyzer : DiagnosticAnalyzer
2424 REFL013MemberIsOfWrongType . Descriptor ,
2525 REFL014PreferGetMemberThenAccessor . Descriptor ,
2626 REFL015UseContainingType . Descriptor ,
27- REFL018ExplicitImplementation . Descriptor ) ;
27+ REFL018ExplicitImplementation . Descriptor ,
28+ REFL019NoMemberMatchesTheTypes . Descriptor ) ;
2829
2930 /// <inheritdoc/>
3031 public override void Initialize ( AnalysisContext context )
@@ -40,17 +41,17 @@ private static void Handle(SyntaxNodeAnalysisContext context)
4041 context . Node is InvocationExpressionSyntax invocation &&
4142 invocation . ArgumentList is ArgumentListSyntax argumentList )
4243 {
43- switch ( TryGetX ( context , out var targetType , out var nameArg , out var targetName , out var target , out var flagsArg , out var effectiveFlags , out var typesArg , out var types ) )
44+ switch ( TryGetX ( context , out var type , out var nameArg , out var memberName , out var member , out var flagsArg , out var effectiveFlags , out var typesArg , out var types ) )
4445 {
4546 case GetXResult . NoMatch :
46- context . ReportDiagnostic ( Diagnostic . Create ( REFL003MemberDoesNotExist . Descriptor , nameArg . GetLocation ( ) , targetType , targetName ) ) ;
47+ context . ReportDiagnostic ( Diagnostic . Create ( REFL003MemberDoesNotExist . Descriptor , nameArg . GetLocation ( ) , type , memberName ) ) ;
4748 break ;
4849
4950 case GetXResult . Ambiguous :
5051 context . ReportDiagnostic ( Diagnostic . Create ( REFL004AmbiguousMatch . Descriptor , argumentList . GetLocation ( ) ) ) ;
5152 break ;
5253
53- case GetXResult . WrongFlags when TryGetExpectedFlags ( target , targetType , out var correctFlags ) :
54+ case GetXResult . WrongFlags when TryGetExpectedFlags ( member , type , out var correctFlags ) :
5455 if ( flagsArg != null )
5556 {
5657 context . ReportDiagnostic (
@@ -80,11 +81,11 @@ context.Node is InvocationExpressionSyntax invocation &&
8081 break ;
8182
8283 case GetXResult . Single :
83- if ( TryGetExpectedFlags ( target , targetType , out var expectedFlags ) &&
84+ if ( TryGetExpectedFlags ( member , type , out var expectedFlags ) &&
8485 effectiveFlags != expectedFlags )
8586 {
8687 if ( flagsArg != null &&
87- HasRedundantFlag ( target , targetType , effectiveFlags ) )
88+ HasRedundantFlag ( member , type , effectiveFlags ) )
8889 {
8990 context . ReportDiagnostic (
9091 Diagnostic . Create (
@@ -95,7 +96,7 @@ context.Node is InvocationExpressionSyntax invocation &&
9596 }
9697
9798 if ( flagsArg == null ||
98- HasMissingFlag ( target , targetType , effectiveFlags ) )
99+ HasMissingFlag ( member , type , effectiveFlags ) )
99100 {
100101 context . ReportDiagnostic (
101102 Diagnostic . Create (
@@ -106,7 +107,7 @@ context.Node is InvocationExpressionSyntax invocation &&
106107 }
107108 }
108109
109- if ( IsPreferGetMemberThenAccessor ( invocation , target , context , out var call ) )
110+ if ( IsPreferGetMemberThenAccessor ( invocation , member , context , out var call ) )
110111 {
111112 context . ReportDiagnostic (
112113 Diagnostic . Create (
@@ -120,7 +121,18 @@ context.Node is InvocationExpressionSyntax invocation &&
120121
121122 case GetXResult . WrongMemberType :
122123 context . ReportDiagnostic (
123- Diagnostic . Create ( REFL013MemberIsOfWrongType . Descriptor , invocation . GetNameLocation ( ) , targetType , targetName , target . GetType ( ) . Name ) ) ;
124+ Diagnostic . Create (
125+ REFL013MemberIsOfWrongType . Descriptor ,
126+ invocation . GetNameLocation ( ) ,
127+ type ,
128+ memberName ,
129+ member . GetType ( ) . Name ) ) ;
130+ break ;
131+ case GetXResult . WrongTypes :
132+ context . ReportDiagnostic (
133+ Diagnostic . Create (
134+ REFL019NoMemberMatchesTheTypes . Descriptor ,
135+ typesArg ? . GetLocation ( ) ?? invocation . GetNameLocation ( ) ) ) ;
124136 break ;
125137 case GetXResult . UseContainingType :
126138 context . ReportDiagnostic (
@@ -129,8 +141,8 @@ context.Node is InvocationExpressionSyntax invocation &&
129141 TargetTypeLocation ( ) ,
130142 ImmutableDictionary < string , string > . Empty . Add (
131143 nameof ( ISymbol . ContainingType ) ,
132- target . ContainingType . ToMinimalDisplayString ( context . SemanticModel , invocation . SpanStart ) ) ,
133- target . ContainingType . Name ) ) ;
144+ member . ContainingType . ToMinimalDisplayString ( context . SemanticModel , invocation . SpanStart ) ) ,
145+ member . ContainingType . Name ) ) ;
134146 break ;
135147 case GetXResult . ExplicitImplementation :
136148 context . ReportDiagnostic (
@@ -139,8 +151,8 @@ context.Node is InvocationExpressionSyntax invocation &&
139151 TargetTypeLocation ( ) ,
140152 ImmutableDictionary < string , string > . Empty . Add (
141153 nameof ( ISymbol . ContainingType ) ,
142- target . ContainingType . ToMinimalDisplayString ( context . SemanticModel , invocation . SpanStart ) ) ,
143- target . Name ) ) ;
154+ member . ContainingType . ToMinimalDisplayString ( context . SemanticModel , invocation . SpanStart ) ) ,
155+ member . Name ) ) ;
144156 break ;
145157 case GetXResult . Unknown :
146158 break ;
0 commit comments