Browse Source

C#: Fix unhandled GD0303 error for nested generic attribute types

Zae 10 months ago
parent
commit
9c99e519c6

+ 13 - 0
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<bool>()]
+    public void MethodWithNestedAttribute()
+    {
+    }
 }
 
 [GenericTypeAttribute<bool>()]
@@ -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
+    {
+    }
+}

+ 1 - 1
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],