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