From e771530de244acc08d53abfa9243e436878547e7 Mon Sep 17 00:00:00 2001 From: Tayrtahn Date: Tue, 5 Aug 2025 00:48:36 -0400 Subject: [PATCH] Mark `AutoGenerateComponentStateAttribute` fields as `readonly` (redo) (#6129) * Mark AutoGenerateComponentStateAttribute fields as readonly * Remove no-longer-valid test case --- .../AfterAutoHandleStateAnalyzerTest.cs | 21 +++++++------------ .../ComponentNetworkGeneratorAuxiliary.cs | 4 ++-- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/Robust.Analyzers.Tests/AfterAutoHandleStateAnalyzerTest.cs b/Robust.Analyzers.Tests/AfterAutoHandleStateAnalyzerTest.cs index 8bbafe314..26c0f1d56 100644 --- a/Robust.Analyzers.Tests/AfterAutoHandleStateAnalyzerTest.cs +++ b/Robust.Analyzers.Tests/AfterAutoHandleStateAnalyzerTest.cs @@ -74,8 +74,6 @@ public sealed class AfterAutoHandleStateAnalyzerTest public sealed class AutoGenNoArgs; [AutoGenerateComponentState(false)] public sealed class AutoGenFalse; - [AutoGenerateComponentState(RaiseAfterAutoHandleState = true)] - public sealed class AutoGenIncorrectConstructorArg; public sealed class Foo : EntitySystem { @@ -96,22 +94,17 @@ public sealed class AfterAutoHandleStateAnalyzerTest // Can't subscribe if first arg is not specified/false SubscribeLocalEvent(); SubscribeLocalEvent(); - - // Can't subscribe with RaiseAfterAutoHandleState = true because that's - // secretly a no-op. - SubscribeLocalEvent(); } } """; await Verifier(code, - // /0/Test0.cs(31,9): error RA0040: Tried to subscribe to AfterAutoHandleStateEvent for 'NotAutoGen' which doesn't have an AutoGenerateComponentState attribute - VerifyCS.Diagnostic(AfterAutoHandleStateAnalyzer.MissingAttribute).WithSpan(31, 9, 31, 69).WithArguments("NotAutoGen"), - // /0/Test0.cs(34,9): error RA0041: Tried to subscribe to AfterAutoHandleStateEvent for 'AutoGenNoArgs' which doesn't have RaiseAfterAutoHandleState set - VerifyCS.Diagnostic(AfterAutoHandleStateAnalyzer.MissingAttributeParam).WithSpan(34, 9, 34, 72).WithArguments("AutoGenNoArgs"), - // /0/Test0.cs(35,9): error RA0041: Tried to subscribe to AfterAutoHandleStateEvent for 'AutoGenFalse' which doesn't have RaiseAfterAutoHandleState set - VerifyCS.Diagnostic(AfterAutoHandleStateAnalyzer.MissingAttributeParam).WithSpan(35, 9, 35, 71).WithArguments("AutoGenFalse"), - // /0/Test0.cs(39,9): error RA0041: Tried to subscribe to AfterAutoHandleStateEvent for 'AutoGenIncorrectConstructorArg' which doesn't have RaiseAfterAutoHandleState set - VerifyCS.Diagnostic(AfterAutoHandleStateAnalyzer.MissingAttributeParam).WithSpan(39, 9, 39, 89).WithArguments("AutoGenIncorrectConstructorArg") ); + // /0/Test0.cs(29,9): error RA0040: Tried to subscribe to AfterAutoHandleStateEvent for 'NotAutoGen' which doesn't have an AutoGenerateComponentState attribute + VerifyCS.Diagnostic(AfterAutoHandleStateAnalyzer.MissingAttribute).WithSpan(29, 9, 29, 69).WithArguments("NotAutoGen"), + // /0/Test0.cs(32,9): error RA0041: Tried to subscribe to AfterAutoHandleStateEvent for 'AutoGenNoArgs' which doesn't have raiseAfterAutoHandleState set + VerifyCS.Diagnostic(AfterAutoHandleStateAnalyzer.MissingAttributeParam).WithSpan(32, 9, 32, 72).WithArguments("AutoGenNoArgs"), + // /0/Test0.cs(33,9): error RA0041: Tried to subscribe to AfterAutoHandleStateEvent for 'AutoGenFalse' which doesn't have raiseAfterAutoHandleState set + VerifyCS.Diagnostic(AfterAutoHandleStateAnalyzer.MissingAttributeParam).WithSpan(33, 9, 33, 71).WithArguments("AutoGenFalse") + ); } } diff --git a/Robust.Shared/Analyzers/ComponentNetworkGeneratorAuxiliary.cs b/Robust.Shared/Analyzers/ComponentNetworkGeneratorAuxiliary.cs index 4ca358776..01a5d39d5 100644 --- a/Robust.Shared/Analyzers/ComponentNetworkGeneratorAuxiliary.cs +++ b/Robust.Shared/Analyzers/ComponentNetworkGeneratorAuxiliary.cs @@ -17,12 +17,12 @@ public sealed class AutoGenerateComponentStateAttribute : Attribute /// If this is true, the autogenerated code will raise a component event /// so that user-defined systems can have effects after handling state without redefining all replication. /// - public bool RaiseAfterAutoHandleState; + public readonly bool RaiseAfterAutoHandleState; /// /// Should delta states be generated for every field. /// - public bool FieldDeltas; + public readonly bool FieldDeltas; public AutoGenerateComponentStateAttribute(bool raiseAfterAutoHandleState = false, bool fieldDeltas = false) {