You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-11 13:10:58 +00:00
C#: Ignore property indexers and report if exported
Ignore property indexers since they are unsupported and report a diagnostic if an user tries to export it.
This commit is contained in:
@@ -168,6 +168,32 @@ namespace Godot.SourceGenerators
|
|||||||
location?.SourceTree?.FilePath));
|
location?.SourceTree?.FilePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void ReportExportedMemberIsIndexer(
|
||||||
|
GeneratorExecutionContext context,
|
||||||
|
ISymbol exportedMemberSymbol
|
||||||
|
)
|
||||||
|
{
|
||||||
|
var locations = exportedMemberSymbol.Locations;
|
||||||
|
var location = locations.FirstOrDefault(l => l.SourceTree != null) ?? locations.FirstOrDefault();
|
||||||
|
|
||||||
|
string message = $"Attempted to export indexer property: " +
|
||||||
|
$"'{exportedMemberSymbol.ToDisplayString()}'";
|
||||||
|
|
||||||
|
string description = $"{message}. Indexer properties can't be exported." +
|
||||||
|
" Remove the '[Export]' attribute.";
|
||||||
|
|
||||||
|
context.ReportDiagnostic(Diagnostic.Create(
|
||||||
|
new DiagnosticDescriptor(id: "GD0105",
|
||||||
|
title: message,
|
||||||
|
messageFormat: message,
|
||||||
|
category: "Usage",
|
||||||
|
DiagnosticSeverity.Error,
|
||||||
|
isEnabledByDefault: true,
|
||||||
|
description),
|
||||||
|
location,
|
||||||
|
location?.SourceTree?.FilePath));
|
||||||
|
}
|
||||||
|
|
||||||
public static void ReportSignalDelegateMissingSuffix(
|
public static void ReportSignalDelegateMissingSuffix(
|
||||||
GeneratorExecutionContext context,
|
GeneratorExecutionContext context,
|
||||||
INamedTypeSymbol delegateSymbol)
|
INamedTypeSymbol delegateSymbol)
|
||||||
|
|||||||
@@ -112,7 +112,8 @@ namespace Godot.SourceGenerators
|
|||||||
|
|
||||||
var propertySymbols = members
|
var propertySymbols = members
|
||||||
.Where(s => !s.IsStatic && s.Kind == SymbolKind.Property)
|
.Where(s => !s.IsStatic && s.Kind == SymbolKind.Property)
|
||||||
.Cast<IPropertySymbol>();
|
.Cast<IPropertySymbol>()
|
||||||
|
.Where(s => !s.IsIndexer);
|
||||||
|
|
||||||
var fieldSymbols = members
|
var fieldSymbols = members
|
||||||
.Where(s => !s.IsStatic && s.Kind == SymbolKind.Field && !s.IsImplicitlyDeclared)
|
.Where(s => !s.IsStatic && s.Kind == SymbolKind.Field && !s.IsImplicitlyDeclared)
|
||||||
|
|||||||
@@ -134,6 +134,12 @@ namespace Godot.SourceGenerators
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (property.IsIndexer)
|
||||||
|
{
|
||||||
|
Common.ReportExportedMemberIsIndexer(context, property);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: We should still restore read-only properties after reloading assembly. Two possible ways: reflection or turn RestoreGodotObjectData into a constructor overload.
|
// TODO: We should still restore read-only properties after reloading assembly. Two possible ways: reflection or turn RestoreGodotObjectData into a constructor overload.
|
||||||
// Ignore properties without a getter or without a setter. Godot properties must be both readable and writable.
|
// Ignore properties without a getter or without a setter. Godot properties must be both readable and writable.
|
||||||
if (property.IsWriteOnly)
|
if (property.IsWriteOnly)
|
||||||
@@ -148,7 +154,6 @@ namespace Godot.SourceGenerators
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var propertyType = property.Type;
|
var propertyType = property.Type;
|
||||||
var marshalType = MarshalUtils.ConvertManagedTypeToMarshalType(propertyType, typeCache);
|
var marshalType = MarshalUtils.ConvertManagedTypeToMarshalType(propertyType, typeCache);
|
||||||
|
|
||||||
|
|||||||
@@ -112,7 +112,8 @@ namespace Godot.SourceGenerators
|
|||||||
|
|
||||||
var propertySymbols = members
|
var propertySymbols = members
|
||||||
.Where(s => !s.IsStatic && s.Kind == SymbolKind.Property)
|
.Where(s => !s.IsStatic && s.Kind == SymbolKind.Property)
|
||||||
.Cast<IPropertySymbol>();
|
.Cast<IPropertySymbol>()
|
||||||
|
.Where(s => !s.IsIndexer);
|
||||||
|
|
||||||
var fieldSymbols = members
|
var fieldSymbols = members
|
||||||
.Where(s => !s.IsStatic && s.Kind == SymbolKind.Field && !s.IsImplicitlyDeclared)
|
.Where(s => !s.IsStatic && s.Kind == SymbolKind.Field && !s.IsImplicitlyDeclared)
|
||||||
|
|||||||
Reference in New Issue
Block a user