From 97045c2cd7c48cf17964f97b6016dc216f99f00e Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 18 Aug 2026 01:15:12 +0000 Subject: [PATCH] Report ZEROS003 and ZEROS004 on property type location Updates ZeroSerializerGenerator to report ZEROS003 and ZEROS004 diagnostics on the property type location instead of the property identifier. Adjusts diagnostic test cases in DiagnosticTests.cs accordingly. --- src/ZeroSerializerGenerator.cs | 17 +++++++++++++++-- tests/Diagnostics/DiagnosticTests.cs | 10 +++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/ZeroSerializerGenerator.cs b/src/ZeroSerializerGenerator.cs index 52628b7..c02ae78 100644 --- a/src/ZeroSerializerGenerator.cs +++ b/src/ZeroSerializerGenerator.cs @@ -357,7 +357,7 @@ private static TypeGenerationModel CreateGenerationModel( generationModel.IsValid = false; executionContext.ReportDiagnostic(Diagnostic.Create( UnsupportedSerializableField, - serializableProperty.Locations.IsDefaultOrEmpty ? null : serializableProperty.Locations[0], + GetPropertyTypeLocation(serializableProperty), serializableProperty.Name, serializableProperty.Type.ToDisplayString())); continue; @@ -368,7 +368,7 @@ private static TypeGenerationModel CreateGenerationModel( generationModel.IsValid = false; executionContext.ReportDiagnostic(Diagnostic.Create( InvalidBlittableArrayElement, - serializableProperty.Locations.IsDefaultOrEmpty ? null : serializableProperty.Locations[0], + GetPropertyTypeLocation(serializableProperty), serializableProperty.Name)); continue; } @@ -790,6 +790,19 @@ private static void ReportBlittableCompatibleNestedStructDiagnostics( return declaredType.Locations.IsDefaultOrEmpty ? null : declaredType.Locations[0]; } + private static Location? GetPropertyTypeLocation(IPropertySymbol propertySymbol) + { + foreach (SyntaxReference declaringSyntaxReference in propertySymbol.DeclaringSyntaxReferences) + { + if (declaringSyntaxReference.GetSyntax() is PropertyDeclarationSyntax propertyDeclaration) + { + return propertyDeclaration.Type.GetLocation(); + } + } + + return propertySymbol.Locations.IsDefaultOrEmpty ? null : propertySymbol.Locations[0]; + } + private static bool TryGetPrimitiveByteCount(ITypeSymbol candidateType, out int byteCount) { switch (candidateType.SpecialType) diff --git a/tests/Diagnostics/DiagnosticTests.cs b/tests/Diagnostics/DiagnosticTests.cs index 54f16fd..1c93cfc 100644 --- a/tests/Diagnostics/DiagnosticTests.cs +++ b/tests/Diagnostics/DiagnosticTests.cs @@ -250,8 +250,8 @@ public struct PackedValue [ZeroSerializer] public class Container { - public PackedValue {|#0:Value|} { get; set; } - public PackedValue? {|#1:OptionalValue|} { get; set; } + public {|#0:PackedValue|} Value { get; set; } + public {|#1:PackedValue?|} OptionalValue { get; set; } } "; @@ -280,7 +280,7 @@ public class UnmarkedClass [ZeroSerializer] public class Container { - public UnmarkedClass {|#0:Value|} { get; set; } + public {|#0:UnmarkedClass|} Value { get; set; } } "; @@ -335,7 +335,7 @@ public struct PackedValue [ZeroSerializer] public class Container { - public PackedValue[] {|#0:Values|} { get; set; } + public {|#0:PackedValue[]|} Values { get; set; } } "; @@ -389,7 +389,7 @@ public struct PackedValue [ZeroSerializer] public class InvalidType { - public PackedValue {|#0:Value|} { get; set; } + public {|#0:PackedValue|} Value { get; set; } } [ZeroSerializer]