diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/NestedInGenericTest.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/NestedInGenericTest.cs new file mode 100644 index 00000000000..01d6ab3820e --- /dev/null +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/NestedInGenericTest.cs @@ -0,0 +1,15 @@ +using Xunit; + +namespace Godot.SourceGenerators.Tests; + +public class NestedInGenericTest +{ + [Fact] + public async void GenerateScriptMethodsTest() + { + await CSharpSourceGeneratorVerifier.Verify( + "NestedInGeneric.cs", + "GenericClass(Of T).NestedClass_ScriptMethods.generated.cs" + ); + } +} diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/GeneratedSources/GenericClass(Of T).NestedClass_ScriptMethods.generated.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/GeneratedSources/GenericClass(Of T).NestedClass_ScriptMethods.generated.cs new file mode 100644 index 00000000000..94ac7422695 --- /dev/null +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/GeneratedSources/GenericClass(Of T).NestedClass_ScriptMethods.generated.cs @@ -0,0 +1,16 @@ +using Godot; +using Godot.NativeInterop; + +partial class GenericClass +{ +partial class NestedClass +{ +#pragma warning disable CS0109 // Disable warning about redundant 'new' keyword + /// + /// Cached StringNames for the methods contained in this class, for fast lookup. + /// + public new class MethodName : global::Godot.GodotObject.MethodName { + } +#pragma warning restore CS0109 +} +} diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/Sources/NestedInGeneric.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/Sources/NestedInGeneric.cs new file mode 100644 index 00000000000..32e12d06873 --- /dev/null +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/Sources/NestedInGeneric.cs @@ -0,0 +1,9 @@ +using Godot; + +public partial class GenericClass +{ + public partial class NestedClass : GodotObject + { + + } +} diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ExtensionMethods.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ExtensionMethods.cs index 46c446169a8..12e25389431 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ExtensionMethods.cs +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ExtensionMethods.cs @@ -183,7 +183,7 @@ namespace Godot.SourceGenerators public static string NameWithTypeParameters(this INamedTypeSymbol symbol) { - return symbol.IsGenericType ? + return symbol.IsGenericType && symbol.TypeParameters.Length > 0 ? string.Concat(symbol.Name, "<", string.Join(", ", symbol.TypeParameters), ">") : symbol.Name; } diff --git a/modules/mono/glue/GodotSharp/Godot.SourceGenerators.Internal/ExtensionMethods.cs b/modules/mono/glue/GodotSharp/Godot.SourceGenerators.Internal/ExtensionMethods.cs index a0bd96412a3..3fc27a29d87 100644 --- a/modules/mono/glue/GodotSharp/Godot.SourceGenerators.Internal/ExtensionMethods.cs +++ b/modules/mono/glue/GodotSharp/Godot.SourceGenerators.Internal/ExtensionMethods.cs @@ -96,7 +96,7 @@ internal static class ExtensionMethods public static string NameWithTypeParameters(this INamedTypeSymbol symbol) { - return symbol.IsGenericType ? + return symbol.IsGenericType && symbol.TypeParameters.Length > 0 ? string.Concat(symbol.Name, "<", string.Join(", ", symbol.TypeParameters), ">") : symbol.Name; }