| | | 1 | | using System.Collections.Generic; |
| | | 2 | | using System.Collections.Immutable; |
| | | 3 | | using System.Linq; |
| | | 4 | | |
| | | 5 | | using Microsoft.CodeAnalysis; |
| | | 6 | | using Microsoft.CodeAnalysis.CSharp; |
| | | 7 | | using Microsoft.CodeAnalysis.CSharp.Syntax; |
| | | 8 | | using Microsoft.CodeAnalysis.Diagnostics; |
| | | 9 | | |
| | | 10 | | using NexusLabs.Needlr.Generators.Models; |
| | | 11 | | using NexusLabs.Needlr.Roslyn.Shared; |
| | | 12 | | |
| | | 13 | | namespace NexusLabs.Needlr.Generators; |
| | | 14 | | |
| | | 15 | | /// <summary> |
| | | 16 | | /// Validates generated-constructor type shapes, field participation, built-in and |
| | | 17 | | /// custom guards, and custom guard alias definitions. |
| | | 18 | | /// </summary> |
| | | 19 | | [DiagnosticAnalyzer(LanguageNames.CSharp)] |
| | | 20 | | public sealed class GeneratedConstructorAnalyzer : DiagnosticAnalyzer |
| | | 21 | | { |
| | | 22 | | private const string GenerateConstructorAttributeName = "GenerateConstructorAttribute"; |
| | | 23 | | private const string ConstructorGuardAttributeName = "ConstructorGuardAttribute"; |
| | | 24 | | private const string ConstructorIgnoreAttributeName = "ConstructorIgnoreAttribute"; |
| | | 25 | | private const string ConstructorGuardDefinitionAttributeName = "ConstructorGuardDefinitionAttribute"; |
| | | 26 | | private const string DefaultGuardMethodName = "Validate"; |
| | | 27 | | |
| | | 28 | | public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => |
| | 2498 | 29 | | ImmutableArray.Create( |
| | 2498 | 30 | | DiagnosticDescriptors.GeneratedConstructorRequiresPartialType, |
| | 2498 | 31 | | DiagnosticDescriptors.GeneratedConstructorUnsupportedTypeShape, |
| | 2498 | 32 | | DiagnosticDescriptors.GeneratedConstructorConflictsWithExplicitConstructor, |
| | 2498 | 33 | | DiagnosticDescriptors.GeneratedConstructorBaseTypeRequiresParameterlessConstructor, |
| | 2498 | 34 | | DiagnosticDescriptors.GeneratedConstructorNoEligibleFields, |
| | 2498 | 35 | | DiagnosticDescriptors.GeneratedConstructorParameterNameCollision, |
| | 2498 | 36 | | DiagnosticDescriptors.ConstructorGuardAttributeHasNoEffect, |
| | 2498 | 37 | | DiagnosticDescriptors.ConstructorGuardAttributeOnIneligibleField, |
| | 2498 | 38 | | DiagnosticDescriptors.InvalidConstructorGuardEnumValue, |
| | 2498 | 39 | | DiagnosticDescriptors.ConstructorGuardIncompatibleWithFieldType, |
| | 2498 | 40 | | DiagnosticDescriptors.ConstructorGuardTypeInvalid, |
| | 2498 | 41 | | DiagnosticDescriptors.ConstructorGuardMethodNameInvalid, |
| | 2498 | 42 | | DiagnosticDescriptors.ConstructorGuardMethodInvalid, |
| | 2498 | 43 | | DiagnosticDescriptors.ConstructorGuardMethodAmbiguous, |
| | 2498 | 44 | | DiagnosticDescriptors.ConstructorGuardDefinitionTargetInvalid, |
| | 2498 | 45 | | DiagnosticDescriptors.ConstructorGuardDefinitionUnresolvedGuard, |
| | 2498 | 46 | | DiagnosticDescriptors.ConstructorGuardAliasUsageArgumentUnsupported, |
| | 2498 | 47 | | DiagnosticDescriptors.ConstructorGuardForwardedArgumentIncompatible); |
| | | 48 | | |
| | | 49 | | public override void Initialize(AnalysisContext context) |
| | | 50 | | { |
| | 186 | 51 | | context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); |
| | 186 | 52 | | context.EnableConcurrentExecution(); |
| | 186 | 53 | | context.RegisterSyntaxNodeAction( |
| | 186 | 54 | | AnalyzeTypeDeclaration, |
| | 186 | 55 | | SyntaxKind.ClassDeclaration, |
| | 186 | 56 | | SyntaxKind.RecordDeclaration); |
| | 186 | 57 | | } |
| | | 58 | | |
| | | 59 | | private static void AnalyzeTypeDeclaration(SyntaxNodeAnalysisContext context) |
| | | 60 | | { |
| | 2102 | 61 | | var typeDeclaration = (TypeDeclarationSyntax)context.Node; |
| | 2102 | 62 | | if (context.SemanticModel.GetDeclaredSymbol(typeDeclaration) is not |
| | 2102 | 63 | | INamedTypeSymbol typeSymbol) |
| | | 64 | | { |
| | 0 | 65 | | return; |
| | | 66 | | } |
| | | 67 | | |
| | 2102 | 68 | | var occurrences = CollectFieldGuardOccurrences( |
| | 2102 | 69 | | context, |
| | 2102 | 70 | | typeDeclaration); |
| | 2102 | 71 | | var classHasTrigger = |
| | 2102 | 72 | | GeneratedConstructorEligibility.HasGenerateConstructorAttribute(typeSymbol) || |
| | 2102 | 73 | | GeneratedConstructorEligibility.HasPositiveFieldGuardTrigger(typeSymbol); |
| | | 74 | | |
| | 2102 | 75 | | ReportFieldOccurrenceDiagnostics( |
| | 2102 | 76 | | context, |
| | 2102 | 77 | | typeSymbol, |
| | 2102 | 78 | | occurrences, |
| | 2102 | 79 | | classHasTrigger); |
| | | 80 | | |
| | 2102 | 81 | | if (!GeneratedConstructorEligibility.IsCanonicalDeclaration( |
| | 2102 | 82 | | typeSymbol, |
| | 2102 | 83 | | typeDeclaration)) |
| | | 84 | | { |
| | 4 | 85 | | return; |
| | | 86 | | } |
| | | 87 | | |
| | 2098 | 88 | | AnalyzeGuardDefinitionTarget(context, typeSymbol); |
| | | 89 | | |
| | 2098 | 90 | | if (!classHasTrigger) |
| | 2007 | 91 | | return; |
| | | 92 | | |
| | 91 | 93 | | if (typeSymbol.IsRecord && |
| | 91 | 94 | | RecordConstructorOverloadDiscoveryHelper |
| | 91 | 95 | | .GetMarkedProperties(typeSymbol).Count > 0) |
| | | 96 | | { |
| | 0 | 97 | | return; |
| | | 98 | | } |
| | | 99 | | |
| | 91 | 100 | | AnalyzeGenerateConstructorEnumArgument(context, typeSymbol); |
| | 91 | 101 | | AnalyzeTypeShape(context, typeDeclaration, typeSymbol); |
| | 91 | 102 | | } |
| | | 103 | | |
| | | 104 | | private static void AnalyzeTypeShape( |
| | | 105 | | SyntaxNodeAnalysisContext context, |
| | | 106 | | TypeDeclarationSyntax typeDeclaration, |
| | | 107 | | INamedTypeSymbol typeSymbol) |
| | | 108 | | { |
| | 91 | 109 | | var location = typeDeclaration.Identifier.GetLocation(); |
| | | 110 | | |
| | 91 | 111 | | if (typeSymbol.IsRecord) |
| | | 112 | | { |
| | 2 | 113 | | context.ReportDiagnostic(Diagnostic.Create( |
| | 2 | 114 | | DiagnosticDescriptors.GeneratedConstructorUnsupportedTypeShape, |
| | 2 | 115 | | location, |
| | 2 | 116 | | typeSymbol.Name, |
| | 2 | 117 | | "a record type")); |
| | | 118 | | } |
| | 89 | 119 | | else if (typeSymbol.ContainingType is not null) |
| | | 120 | | { |
| | 2 | 121 | | context.ReportDiagnostic(Diagnostic.Create( |
| | 2 | 122 | | DiagnosticDescriptors.GeneratedConstructorUnsupportedTypeShape, |
| | 2 | 123 | | location, |
| | 2 | 124 | | typeSymbol.Name, |
| | 2 | 125 | | "a nested type")); |
| | | 126 | | } |
| | | 127 | | |
| | 91 | 128 | | if (!GeneratedConstructorEligibility.IsDeclaredPartial(typeSymbol)) |
| | | 129 | | { |
| | 2 | 130 | | context.ReportDiagnostic(Diagnostic.Create( |
| | 2 | 131 | | DiagnosticDescriptors.GeneratedConstructorRequiresPartialType, |
| | 2 | 132 | | location, |
| | 2 | 133 | | typeSymbol.Name)); |
| | | 134 | | } |
| | | 135 | | |
| | 91 | 136 | | if (GeneratedConstructorEligibility.HasExplicitInstanceConstructor(typeSymbol)) |
| | | 137 | | { |
| | 6 | 138 | | context.ReportDiagnostic(Diagnostic.Create( |
| | 6 | 139 | | DiagnosticDescriptors.GeneratedConstructorConflictsWithExplicitConstructor, |
| | 6 | 140 | | location, |
| | 6 | 141 | | typeSymbol.Name)); |
| | | 142 | | } |
| | | 143 | | |
| | 91 | 144 | | if (typeSymbol.BaseType is not null && |
| | 91 | 145 | | typeSymbol.BaseType.SpecialType != SpecialType.System_Object && |
| | 91 | 146 | | !GeneratedConstructorEligibility.HasAccessibleParameterlessConstructor( |
| | 91 | 147 | | typeSymbol.BaseType)) |
| | | 148 | | { |
| | 2 | 149 | | context.ReportDiagnostic(Diagnostic.Create( |
| | 2 | 150 | | DiagnosticDescriptors.GeneratedConstructorBaseTypeRequiresParameterlessConstructor, |
| | 2 | 151 | | location, |
| | 2 | 152 | | typeSymbol.Name, |
| | 2 | 153 | | typeSymbol.BaseType.Name)); |
| | | 154 | | } |
| | | 155 | | |
| | 91 | 156 | | var eligibleFields = |
| | 91 | 157 | | GeneratedConstructorEligibility.GetEligibleConstructorFields(typeSymbol); |
| | 91 | 158 | | if (eligibleFields.Count == 0) |
| | | 159 | | { |
| | 2 | 160 | | context.ReportDiagnostic(Diagnostic.Create( |
| | 2 | 161 | | DiagnosticDescriptors.GeneratedConstructorNoEligibleFields, |
| | 2 | 162 | | location, |
| | 2 | 163 | | typeSymbol.Name)); |
| | 2 | 164 | | return; |
| | | 165 | | } |
| | | 166 | | |
| | 89 | 167 | | var seenParameterNames = new HashSet<string>( |
| | 89 | 168 | | System.StringComparer.Ordinal); |
| | 362 | 169 | | foreach (var field in eligibleFields) |
| | | 170 | | { |
| | 92 | 171 | | var parameterName = |
| | 92 | 172 | | ConstructorGenerationDiscoveryHelper.GetParameterName(field.Name); |
| | 92 | 173 | | if (!seenParameterNames.Add(parameterName)) |
| | | 174 | | { |
| | 2 | 175 | | context.ReportDiagnostic(Diagnostic.Create( |
| | 2 | 176 | | DiagnosticDescriptors.GeneratedConstructorParameterNameCollision, |
| | 2 | 177 | | location, |
| | 2 | 178 | | typeSymbol.Name, |
| | 2 | 179 | | parameterName)); |
| | | 180 | | } |
| | | 181 | | } |
| | 89 | 182 | | } |
| | | 183 | | |
| | | 184 | | private static void AnalyzeGenerateConstructorEnumArgument( |
| | | 185 | | SyntaxNodeAnalysisContext context, |
| | | 186 | | INamedTypeSymbol typeSymbol) |
| | | 187 | | { |
| | 230 | 188 | | foreach (var attribute in typeSymbol.GetAttributes()) |
| | | 189 | | { |
| | 24 | 190 | | if (attribute.AttributeClass is not { } attrClass || |
| | 24 | 191 | | !GeneratedConstructorEligibility.IsNeedlrGeneratorsAttribute( |
| | 24 | 192 | | attrClass, |
| | 24 | 193 | | GenerateConstructorAttributeName) || |
| | 24 | 194 | | attribute.ConstructorArguments.Length == 0) |
| | | 195 | | { |
| | | 196 | | continue; |
| | | 197 | | } |
| | | 198 | | |
| | 2 | 199 | | ConstructorGuardAnalysisHelper.TryReportUndefinedEnum( |
| | 2 | 200 | | context, |
| | 2 | 201 | | ConstructorGuardAnalysisHelper.GetAttributeLocation( |
| | 2 | 202 | | context, |
| | 2 | 203 | | attribute), |
| | 2 | 204 | | attribute.ConstructorArguments[0]); |
| | | 205 | | } |
| | 91 | 206 | | } |
| | | 207 | | |
| | | 208 | | private static List<ConstructorGuardOccurrence> CollectFieldGuardOccurrences( |
| | | 209 | | SyntaxNodeAnalysisContext context, |
| | | 210 | | TypeDeclarationSyntax typeDeclaration) |
| | | 211 | | { |
| | 2102 | 212 | | var occurrences = new List<ConstructorGuardOccurrence>(); |
| | | 213 | | |
| | 4672 | 214 | | foreach (var fieldDeclaration in typeDeclaration.Members |
| | 2102 | 215 | | .OfType<FieldDeclarationSyntax>()) |
| | | 216 | | { |
| | 936 | 217 | | foreach (var variable in fieldDeclaration.Declaration.Variables) |
| | | 218 | | { |
| | 234 | 219 | | if (context.SemanticModel.GetDeclaredSymbol(variable) is not |
| | 234 | 220 | | IFieldSymbol fieldSymbol) |
| | | 221 | | { |
| | | 222 | | continue; |
| | | 223 | | } |
| | | 224 | | |
| | 234 | 225 | | var ineligibilityReason = |
| | 234 | 226 | | GeneratedConstructorEligibility.GetFieldIneligibilityReason( |
| | 234 | 227 | | fieldSymbol); |
| | | 228 | | |
| | 636 | 229 | | foreach (var attribute in fieldSymbol.GetAttributes()) |
| | | 230 | | { |
| | 84 | 231 | | if (attribute.AttributeClass is not { } attrClass) |
| | | 232 | | continue; |
| | | 233 | | |
| | 84 | 234 | | if (GeneratedConstructorEligibility.IsNeedlrGeneratorsAttribute( |
| | 84 | 235 | | attrClass, |
| | 84 | 236 | | ConstructorIgnoreAttributeName)) |
| | | 237 | | { |
| | 3 | 238 | | occurrences.Add(new ConstructorGuardOccurrence( |
| | 3 | 239 | | fieldSymbol, |
| | 3 | 240 | | fieldSymbol.Type, |
| | 3 | 241 | | "field", |
| | 3 | 242 | | attribute, |
| | 3 | 243 | | ConstructorGuardOccurrenceKind.Ignore, |
| | 3 | 244 | | ineligibilityReason, |
| | 3 | 245 | | null, |
| | 3 | 246 | | null, |
| | 3 | 247 | | false, |
| | 3 | 248 | | false)); |
| | 3 | 249 | | continue; |
| | | 250 | | } |
| | | 251 | | |
| | 81 | 252 | | if (GeneratedConstructorEligibility.IsNeedlrGeneratorsAttribute( |
| | 81 | 253 | | attrClass, |
| | 81 | 254 | | ConstructorGuardAttributeName)) |
| | | 255 | | { |
| | 52 | 256 | | occurrences.Add( |
| | 52 | 257 | | ConstructorGuardAnalysisHelper.BuildDirectGuardOccurrence( |
| | 52 | 258 | | fieldSymbol, |
| | 52 | 259 | | fieldSymbol.Type, |
| | 52 | 260 | | "field", |
| | 52 | 261 | | attribute, |
| | 52 | 262 | | ineligibilityReason)); |
| | 52 | 263 | | continue; |
| | | 264 | | } |
| | | 265 | | |
| | 29 | 266 | | if (!ConstructorGuardAnalysisHelper.TryGetGuardDefinition( |
| | 29 | 267 | | attrClass, |
| | 29 | 268 | | out var guardType, |
| | 29 | 269 | | out var methodName, |
| | 29 | 270 | | out var methodNameExplicit)) |
| | | 271 | | { |
| | | 272 | | continue; |
| | | 273 | | } |
| | | 274 | | |
| | 29 | 275 | | occurrences.Add( |
| | 29 | 276 | | ConstructorGuardAnalysisHelper.BuildAliasOccurrence( |
| | 29 | 277 | | fieldSymbol, |
| | 29 | 278 | | fieldSymbol.Type, |
| | 29 | 279 | | "field", |
| | 29 | 280 | | attribute, |
| | 29 | 281 | | ineligibilityReason, |
| | 29 | 282 | | guardType, |
| | 29 | 283 | | methodName, |
| | 29 | 284 | | methodNameExplicit, |
| | 29 | 285 | | attrClass.DeclaringSyntaxReferences.Length > 0)); |
| | | 286 | | } |
| | | 287 | | } |
| | | 288 | | } |
| | | 289 | | |
| | 2102 | 290 | | return occurrences; |
| | | 291 | | } |
| | | 292 | | |
| | | 293 | | private static void ReportFieldOccurrenceDiagnostics( |
| | | 294 | | SyntaxNodeAnalysisContext context, |
| | | 295 | | INamedTypeSymbol typeSymbol, |
| | | 296 | | IReadOnlyList<ConstructorGuardOccurrence> occurrences, |
| | | 297 | | bool classHasTrigger) |
| | | 298 | | { |
| | 4372 | 299 | | foreach (var occurrence in occurrences) |
| | | 300 | | { |
| | 84 | 301 | | var location = |
| | 84 | 302 | | ConstructorGuardAnalysisHelper.GetAttributeLocation( |
| | 84 | 303 | | context, |
| | 84 | 304 | | occurrence.Attribute); |
| | | 305 | | |
| | 84 | 306 | | if (occurrence.IneligibilityReason is { } reason) |
| | | 307 | | { |
| | 12 | 308 | | context.ReportDiagnostic(Diagnostic.Create( |
| | 12 | 309 | | DiagnosticDescriptors.ConstructorGuardAttributeOnIneligibleField, |
| | 12 | 310 | | location, |
| | 12 | 311 | | occurrence.Member.Name, |
| | 12 | 312 | | reason)); |
| | 12 | 313 | | continue; |
| | | 314 | | } |
| | | 315 | | |
| | 72 | 316 | | if (occurrence.Kind == ConstructorGuardOccurrenceKind.Ignore && |
| | 72 | 317 | | !classHasTrigger) |
| | | 318 | | { |
| | 2 | 319 | | context.ReportDiagnostic(Diagnostic.Create( |
| | 2 | 320 | | DiagnosticDescriptors.ConstructorGuardAttributeHasNoEffect, |
| | 2 | 321 | | location, |
| | 2 | 322 | | occurrence.Member.Name, |
| | 2 | 323 | | "[ConstructorIgnore]")); |
| | 2 | 324 | | continue; |
| | | 325 | | } |
| | | 326 | | |
| | 70 | 327 | | if (occurrence.Kind == |
| | 70 | 328 | | ConstructorGuardOccurrenceKind.BuiltInNone && |
| | 70 | 329 | | !classHasTrigger) |
| | | 330 | | { |
| | 2 | 331 | | context.ReportDiagnostic(Diagnostic.Create( |
| | 2 | 332 | | DiagnosticDescriptors.ConstructorGuardAttributeHasNoEffect, |
| | 2 | 333 | | location, |
| | 2 | 334 | | occurrence.Member.Name, |
| | 2 | 335 | | "[ConstructorGuard(ConstructorGuardKind.None)]")); |
| | 2 | 336 | | continue; |
| | | 337 | | } |
| | | 338 | | |
| | 68 | 339 | | ConstructorGuardAnalysisHelper.AnalyzePositiveGuardOccurrence( |
| | 68 | 340 | | context, |
| | 68 | 341 | | typeSymbol, |
| | 68 | 342 | | occurrence, |
| | 68 | 343 | | location); |
| | | 344 | | } |
| | 2102 | 345 | | } |
| | | 346 | | |
| | | 347 | | private static void AnalyzeGuardDefinitionTarget( |
| | | 348 | | SyntaxNodeAnalysisContext context, |
| | | 349 | | INamedTypeSymbol typeSymbol) |
| | | 350 | | { |
| | 7698 | 351 | | foreach (var attribute in typeSymbol.GetAttributes()) |
| | | 352 | | { |
| | 1751 | 353 | | if (attribute.AttributeClass is not { } attrClass || |
| | 1751 | 354 | | !GeneratedConstructorEligibility.IsNeedlrGeneratorsAttribute( |
| | 1751 | 355 | | attrClass, |
| | 1751 | 356 | | ConstructorGuardDefinitionAttributeName)) |
| | | 357 | | { |
| | | 358 | | continue; |
| | | 359 | | } |
| | | 360 | | |
| | 38 | 361 | | var location = |
| | 38 | 362 | | ConstructorGuardAnalysisHelper.GetAttributeLocation( |
| | 38 | 363 | | context, |
| | 38 | 364 | | attribute); |
| | 38 | 365 | | var targetInvalidReason = |
| | 38 | 366 | | ConstructorGuardAnalysisHelper.GetGuardDefinitionTargetInvalidReason( |
| | 38 | 367 | | typeSymbol); |
| | 38 | 368 | | if (targetInvalidReason is not null) |
| | | 369 | | { |
| | 4 | 370 | | context.ReportDiagnostic(Diagnostic.Create( |
| | 4 | 371 | | DiagnosticDescriptors.ConstructorGuardDefinitionTargetInvalid, |
| | 4 | 372 | | location, |
| | 4 | 373 | | typeSymbol.Name, |
| | 4 | 374 | | targetInvalidReason)); |
| | 4 | 375 | | continue; |
| | | 376 | | } |
| | | 377 | | |
| | 34 | 378 | | if (attribute.ConstructorArguments.Length == 0 || |
| | 34 | 379 | | attribute.ConstructorArguments[0].Value is not ITypeSymbol guardType || |
| | 34 | 380 | | guardType.TypeKind == TypeKind.Error) |
| | | 381 | | { |
| | 2 | 382 | | context.ReportDiagnostic(Diagnostic.Create( |
| | 2 | 383 | | DiagnosticDescriptors.ConstructorGuardDefinitionUnresolvedGuard, |
| | 2 | 384 | | location, |
| | 2 | 385 | | typeSymbol.Name, |
| | 2 | 386 | | "the guard type could not be resolved")); |
| | 2 | 387 | | continue; |
| | | 388 | | } |
| | | 389 | | |
| | 32 | 390 | | if (!context.Compilation.IsSymbolAccessibleWithin( |
| | 32 | 391 | | guardType, |
| | 32 | 392 | | typeSymbol)) |
| | | 393 | | { |
| | 0 | 394 | | context.ReportDiagnostic(Diagnostic.Create( |
| | 0 | 395 | | DiagnosticDescriptors.ConstructorGuardDefinitionUnresolvedGuard, |
| | 0 | 396 | | location, |
| | 0 | 397 | | typeSymbol.Name, |
| | 0 | 398 | | $"'{guardType.ToDisplayString()}' is not accessible from '{typeSymbol.ToDisplayString()}'")); |
| | 0 | 399 | | continue; |
| | | 400 | | } |
| | | 401 | | |
| | 32 | 402 | | var methodNameExplicit = |
| | 32 | 403 | | attribute.ConstructorArguments.Length > 1 && |
| | 32 | 404 | | attribute.ConstructorArguments[1].Value is string; |
| | 32 | 405 | | var methodName = methodNameExplicit |
| | 32 | 406 | | ? (string)attribute.ConstructorArguments[1].Value! |
| | 32 | 407 | | : DefaultGuardMethodName; |
| | 32 | 408 | | if (methodNameExplicit && string.IsNullOrWhiteSpace(methodName)) |
| | | 409 | | { |
| | 0 | 410 | | context.ReportDiagnostic(Diagnostic.Create( |
| | 0 | 411 | | DiagnosticDescriptors.ConstructorGuardDefinitionUnresolvedGuard, |
| | 0 | 412 | | location, |
| | 0 | 413 | | typeSymbol.Name, |
| | 0 | 414 | | "the guard method name must not be empty or consist only of white space")); |
| | 0 | 415 | | continue; |
| | | 416 | | } |
| | | 417 | | |
| | 32 | 418 | | var resolution = |
| | 32 | 419 | | ConstructorGuardAnalysisHelper.TryResolveGuardMethod( |
| | 32 | 420 | | context.Compilation, |
| | 32 | 421 | | typeSymbol, |
| | 32 | 422 | | guardType, |
| | 32 | 423 | | methodName, |
| | 32 | 424 | | null, |
| | 32 | 425 | | "member", |
| | 32 | 426 | | ImmutableArray<ITypeSymbol>.Empty, |
| | 32 | 427 | | out _, |
| | 32 | 428 | | out var reason, |
| | 32 | 429 | | out _); |
| | 32 | 430 | | if (resolution == GuardMethodResolution.NotFound) |
| | | 431 | | { |
| | 2 | 432 | | context.ReportDiagnostic(Diagnostic.Create( |
| | 2 | 433 | | DiagnosticDescriptors.ConstructorGuardDefinitionUnresolvedGuard, |
| | 2 | 434 | | location, |
| | 2 | 435 | | typeSymbol.Name, |
| | 2 | 436 | | reason ?? "no compatible guard method was found")); |
| | | 437 | | } |
| | | 438 | | } |
| | 2098 | 439 | | } |
| | | 440 | | } |