mirror of
https://github.com/godotengine/godot.git
synced 2025-11-01 06:01:14 +00:00
Fix GD0107 not applying to arrays and dictionaries containing nodes
This commit is contained in:
parent
4e5ed0bbfb
commit
8aa444d212
3 changed files with 99 additions and 19 deletions
|
|
@ -196,16 +196,13 @@ namespace Godot.SourceGenerators
|
|||
continue;
|
||||
}
|
||||
|
||||
if (marshalType == MarshalType.GodotObjectOrDerived)
|
||||
if (!isNode && MemberHasNodeType(propertyType, marshalType.Value))
|
||||
{
|
||||
if (!isNode && propertyType.InheritsFrom("GodotSharp", GodotClasses.Node))
|
||||
{
|
||||
context.ReportDiagnostic(Diagnostic.Create(
|
||||
Common.OnlyNodesShouldExportNodesRule,
|
||||
property.Locations.FirstLocationWithSourceTreeOrDefault()
|
||||
));
|
||||
continue;
|
||||
}
|
||||
context.ReportDiagnostic(Diagnostic.Create(
|
||||
Common.OnlyNodesShouldExportNodesRule,
|
||||
property.Locations.FirstLocationWithSourceTreeOrDefault()
|
||||
));
|
||||
continue;
|
||||
}
|
||||
|
||||
var propertyDeclarationSyntax = property.DeclaringSyntaxReferences
|
||||
|
|
@ -315,16 +312,13 @@ namespace Godot.SourceGenerators
|
|||
continue;
|
||||
}
|
||||
|
||||
if (marshalType == MarshalType.GodotObjectOrDerived)
|
||||
if (!isNode && MemberHasNodeType(fieldType, marshalType.Value))
|
||||
{
|
||||
if (!isNode && fieldType.InheritsFrom("GodotSharp", GodotClasses.Node))
|
||||
{
|
||||
context.ReportDiagnostic(Diagnostic.Create(
|
||||
Common.OnlyNodesShouldExportNodesRule,
|
||||
field.Locations.FirstLocationWithSourceTreeOrDefault()
|
||||
));
|
||||
continue;
|
||||
}
|
||||
context.ReportDiagnostic(Diagnostic.Create(
|
||||
Common.OnlyNodesShouldExportNodesRule,
|
||||
field.Locations.FirstLocationWithSourceTreeOrDefault()
|
||||
));
|
||||
continue;
|
||||
}
|
||||
|
||||
EqualsValueClauseSyntax? initializer = field.DeclaringSyntaxReferences
|
||||
|
|
@ -424,6 +418,27 @@ namespace Godot.SourceGenerators
|
|||
context.AddSource(uniqueHint, SourceText.From(source.ToString(), Encoding.UTF8));
|
||||
}
|
||||
|
||||
private static bool MemberHasNodeType(ITypeSymbol memberType, MarshalType marshalType)
|
||||
{
|
||||
if (marshalType == MarshalType.GodotObjectOrDerived)
|
||||
{
|
||||
return memberType.InheritsFrom("GodotSharp", GodotClasses.Node);
|
||||
}
|
||||
if (marshalType == MarshalType.GodotObjectOrDerivedArray)
|
||||
{
|
||||
var elementType = ((IArrayTypeSymbol)memberType).ElementType;
|
||||
return elementType.InheritsFrom("GodotSharp", GodotClasses.Node);
|
||||
}
|
||||
if (memberType is INamedTypeSymbol { IsGenericType: true } genericType)
|
||||
{
|
||||
return genericType.TypeArguments
|
||||
.Any(static typeArgument
|
||||
=> typeArgument.InheritsFrom("GodotSharp", GodotClasses.Node));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private struct ExportedPropertyMetadata
|
||||
{
|
||||
public ExportedPropertyMetadata(string name, MarshalType type, ITypeSymbol typeSymbol, string? value)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue