66using System . Linq ;
77
88using Microsoft . CodeAnalysis ;
9+ using Microsoft . CodeAnalysis . CSharp . Syntax ;
910
1011using ReactiveMarbles . RoslynHelpers ;
1112
@@ -43,10 +44,12 @@ public static List<MethodMetadata> CheckMetadata(GeneratorExecutionContext conte
4344 {
4445 if ( childConstructor . TypeName == metadataMethod . InterfaceTypeName )
4546 {
47+ var location = childConstructor . Parameter . GetLocation ( metadataMethod . MethodInvocation ) ;
48+
4649 context . ReportDiagnostic (
4750 Diagnostic . Create (
4851 DiagnosticWarnings . ConstructorsMustNotHaveCircularDependency ,
49- childConstructor . Parameter . Locations . FirstOrDefault ( x => x is not null ) ?? metadataMethod . MethodInvocation . GetLocation ( ) ) ) ;
52+ location ) ) ;
5053 isError = true ;
5154 }
5255 }
@@ -65,10 +68,12 @@ public static List<MethodMetadata> CheckMetadata(GeneratorExecutionContext conte
6568
6669 if ( metadataDependencies . TryGetValue ( lazyType . ToDisplayString ( RoslynCommonHelpers . TypeFormat ) , out dependencyMethod ) && ! dependencyMethod . IsLazy )
6770 {
71+ var location = constructorDependency . Parameter . GetLocation ( metadataMethod . MethodInvocation ) ;
72+
6873 context . ReportDiagnostic (
6974 Diagnostic . Create (
7075 DiagnosticWarnings . LazyParameterNotRegisteredLazy ,
71- constructorDependency . Parameter . Locations . FirstOrDefault ( x => x is not null ) ?? metadataMethod . MethodInvocation . GetLocation ( ) ,
76+ location ,
7277 metadataMethod . ConcreteTypeName ,
7378 constructorDependency . Parameter . Name ) ) ;
7479 isError = true ;
@@ -84,5 +89,17 @@ public static List<MethodMetadata> CheckMetadata(GeneratorExecutionContext conte
8489
8590 return methods ;
8691 }
92+
93+ private static Location GetLocation ( this ISymbol symbol , InvocationExpressionSyntax backupInvocation )
94+ {
95+ var location = symbol . Locations . FirstOrDefault ( ) ;
96+
97+ if ( location ? . Kind != LocationKind . SourceFile )
98+ {
99+ location = backupInvocation . GetLocation ( ) ;
100+ }
101+
102+ return location ;
103+ }
87104 }
88105}
0 commit comments