From b8fbe5e4653c9d3f54b43efe53d6108ea63d3825 Mon Sep 17 00:00:00 2001 From: faint <46868845+ficcialfaint@users.noreply.github.com> Date: Wed, 3 Jan 2024 09:24:08 +0300 Subject: [PATCH] Compiler error for AutoNetworkedField fields in a component without a AutoGenerateComponentState attribute (#4670) * yeah * remove autonetfield --------- Co-authored-by: metalgearsloth --- .../ComponentNetworkGenerator.cs | 27 +++++++++++++++++++ .../Light/SharedPointLightComponent.cs | 8 +++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/Robust.Shared.CompNetworkGenerator/ComponentNetworkGenerator.cs b/Robust.Shared.CompNetworkGenerator/ComponentNetworkGenerator.cs index 71da4a700..8221fc3d9 100644 --- a/Robust.Shared.CompNetworkGenerator/ComponentNetworkGenerator.cs +++ b/Robust.Shared.CompNetworkGenerator/ComponentNetworkGenerator.cs @@ -315,6 +315,8 @@ public partial class {componentName} { var symbols = new List<(INamedTypeSymbol, AttributeData)>(); var attributeSymbol = comp.GetTypeByMetadataName(ClassAttributeName); + var fieldAttr = comp.GetTypeByMetadataName(MemberAttributeName); + foreach (var candidateClass in receiver.CandidateClasses) { var model = comp.GetSemanticModel(candidateClass.SyntaxTree); @@ -325,6 +327,31 @@ public partial class {componentName} if (relevantAttribute == null) { + if (typeSymbol == null) + continue; + + foreach (var mem in typeSymbol.GetMembers()) + { + var attribute = mem.GetAttributes().FirstOrDefault(a => + a.AttributeClass != null && + a.AttributeClass.Equals(fieldAttr, SymbolEqualityComparer.Default)); + + if (attribute == null) + continue; + + var msg = "Field is marked with [AutoNetworkedField], but its class has no [AutoGenerateComponentState] attribute."; + context.ReportDiagnostic( + Diagnostic.Create( + new DiagnosticDescriptor( + "RXN0007", + msg, + msg, + "Usage", + DiagnosticSeverity.Error, + true), + candidateClass.Keyword.GetLocation())); + } + continue; } diff --git a/Robust.Shared/GameObjects/Components/Light/SharedPointLightComponent.cs b/Robust.Shared/GameObjects/Components/Light/SharedPointLightComponent.cs index b601493bc..53b503c70 100644 --- a/Robust.Shared/GameObjects/Components/Light/SharedPointLightComponent.cs +++ b/Robust.Shared/GameObjects/Components/Light/SharedPointLightComponent.cs @@ -13,7 +13,7 @@ namespace Robust.Shared.GameObjects public abstract partial class SharedPointLightComponent : Component { [ViewVariables(VVAccess.ReadWrite)] - [DataField("color"), AutoNetworkedField] + [DataField("color")] [Animatable] public Color Color { get; set; } = Color.White; @@ -26,17 +26,17 @@ namespace Robust.Shared.GameObjects public Vector2 Offset = Vector2.Zero; [ViewVariables(VVAccess.ReadWrite)] - [DataField("energy"), AutoNetworkedField] + [DataField("energy")] [Animatable] public float Energy { get; set; } = 1f; - [DataField("softness"), AutoNetworkedField, Animatable] + [DataField("softness"), Animatable] public float Softness { get; set; } = 1f; /// /// Whether this pointlight should cast shadows /// - [DataField("castShadows"), AutoNetworkedField] + [DataField("castShadows")] public bool CastShadows = true; [Access(typeof(SharedPointLightSystem))]