Compiler error for AutoNetworkedField fields in a component without a AutoGenerateComponentState attribute (#4670)

* yeah

* remove autonetfield

---------

Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
faint
2024-01-03 09:24:08 +03:00
committed by GitHub
parent 32049e34f2
commit b8fbe5e465
2 changed files with 31 additions and 4 deletions

View File

@@ -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;
}

View File

@@ -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;
/// <summary>
/// Whether this pointlight should cast shadows
/// </summary>
[DataField("castShadows"), AutoNetworkedField]
[DataField("castShadows")]
public bool CastShadows = true;
[Access(typeof(SharedPointLightSystem))]