diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/Sources/MustBeVariant.GD0301.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/Sources/MustBeVariant.GD0301.cs index 053ae36ae76..5654060d382 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/Sources/MustBeVariant.GD0301.cs +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/Sources/MustBeVariant.GD0301.cs @@ -395,6 +395,11 @@ public class MustBeVariantAnnotatedMethods public void MethodWithWrongAttribute() { } + + [NestedGenericTypeAttributeContainer.NestedGenericTypeAttribute()] + public void MethodWithNestedAttribute() + { + } } [GenericTypeAttribute()] @@ -657,3 +662,11 @@ public class ClassNonVariantAnnotated public class GenericTypeAttribute<[MustBeVariant] T> : Attribute { } + +public class NestedGenericTypeAttributeContainer +{ + [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] + public class NestedGenericTypeAttribute<[MustBeVariant] T> : Attribute + { + } +} diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MustBeVariantAnalyzer.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MustBeVariantAnalyzer.cs index e894e7a86cf..a72a8c58801 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MustBeVariantAnalyzer.cs +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MustBeVariantAnalyzer.cs @@ -135,7 +135,7 @@ namespace Godot.SourceGenerators { ITypeParameterSymbol? typeParamSymbol = parentSymbol switch { - IMethodSymbol methodSymbol when parentSyntax.Parent is AttributeSyntax && + IMethodSymbol methodSymbol when parentSyntax.Ancestors().Any(s => s is AttributeSyntax) && methodSymbol.ContainingType.TypeParameters.Length > 0 => methodSymbol.ContainingType.TypeParameters[typeArgumentIndex],