Skip to content

Commit 0e0ef3c

Browse files
committed
Merge pull request godotengine#91368 from raulsntos/dotnet/must-be-variant-dynamic
C#: Ignore late bound methods in MustBeVariantAnalyzer
2 parents 7733ecd + 1510f88 commit 0e0ef3c

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/Sources/MustBeVariant.GD0301.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ public void MethodCallsOk()
6666
Method<Rid[]>();
6767
}
6868

69+
public void MethodCallDynamic()
70+
{
71+
dynamic self = this;
72+
self.Method<object>();
73+
}
74+
6975
public void Method<[MustBeVariant] T>()
7076
{
7177
}

modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MustBeVariantAnalyzer.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,18 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context)
5050
var typeSymbol = sm.GetSymbolInfo(typeSyntax).Symbol as ITypeSymbol;
5151
Helper.ThrowIfNull(typeSymbol);
5252

53-
var parentSymbol = sm.GetSymbolInfo(parentSyntax).Symbol;
54-
Helper.ThrowIfNull(parentSymbol);
53+
var parentSymbolInfo = sm.GetSymbolInfo(parentSyntax);
54+
var parentSymbol = parentSymbolInfo.Symbol;
55+
if (parentSymbol == null)
56+
{
57+
if (parentSymbolInfo.CandidateReason == CandidateReason.LateBound)
58+
{
59+
// Invocations on dynamic are late bound so we can't retrieve the symbol.
60+
continue;
61+
}
62+
63+
Helper.ThrowIfNull(parentSymbol);
64+
}
5565

5666
if (!ShouldCheckTypeArgument(context, parentSyntax, parentSymbol, typeSyntax, typeSymbol, i))
5767
{

0 commit comments

Comments
 (0)