From 973a3c3cb49c6729a1b01b0b1b87b0bc0624fecd Mon Sep 17 00:00:00 2001 From: GeWuYou <95328647+GeWuYou@users.noreply.github.com> Date: Mon, 13 Apr 2026 20:18:47 +0800 Subject: [PATCH] =?UTF-8?q?test(registration):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=B3=A8=E5=86=8C=E5=AF=BC=E5=87=BA=E9=9B=86?= =?UTF-8?q?=E5=90=88=E7=94=9F=E6=88=90=E5=99=A8=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加了批量注册方法生成的基础功能测试 - 添加了集合元素类型推断失败时的诊断报告测试 - 添加了数组参数注册方法的生成测试 - 添加了从继承接口获取注册方法的测试 - 添加了显式接口实现成员不可访问的诊断测试 - 添加了从基类获取注册方法的测试 - 添加了从基类获取注册器成员的测试 - 添加了非实例可读集合成员的诊断测试 - 添加了非实例可读注册器成员的诊断测试 - 添加了注册方法不可访问的诊断测试 - 添加了属性参数无效时的诊断测试 - 添加了多个分部声明时只生成一个源文件的测试 --- .../AutoRegisterExportedCollectionsGeneratorTests.cs | 3 +-- .../AutoRegisterExportedCollectionsGenerator.cs | 8 ++++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/GFramework.Godot.SourceGenerators.Tests/Registration/AutoRegisterExportedCollectionsGeneratorTests.cs b/GFramework.Godot.SourceGenerators.Tests/Registration/AutoRegisterExportedCollectionsGeneratorTests.cs index 1a9afec6..3a67d3c5 100644 --- a/GFramework.Godot.SourceGenerators.Tests/Registration/AutoRegisterExportedCollectionsGeneratorTests.cs +++ b/GFramework.Godot.SourceGenerators.Tests/Registration/AutoRegisterExportedCollectionsGeneratorTests.cs @@ -327,8 +327,7 @@ public class AutoRegisterExportedCollectionsGeneratorTests { Sources = { source } }, - DisabledDiagnostics = { "GF_Common_Trace_001" }, - TestBehaviors = TestBehaviors.SkipGeneratedSourcesCheck + DisabledDiagnostics = { "GF_Common_Trace_001" } }; test.ExpectedDiagnostics.Add(new DiagnosticResult("GF_AutoExport_003", DiagnosticSeverity.Error) diff --git a/GFramework.Godot.SourceGenerators/Registration/AutoRegisterExportedCollectionsGenerator.cs b/GFramework.Godot.SourceGenerators/Registration/AutoRegisterExportedCollectionsGenerator.cs index d6fe8db3..12589767 100644 --- a/GFramework.Godot.SourceGenerators/Registration/AutoRegisterExportedCollectionsGenerator.cs +++ b/GFramework.Godot.SourceGenerators/Registration/AutoRegisterExportedCollectionsGenerator.cs @@ -357,15 +357,23 @@ public sealed class AutoRegisterExportedCollectionsGenerator : IIncrementalGener INamedTypeSymbol registryType, string registerMethodName) { + // Start from the declared registry type so directly declared overloads win the cheap checks + // before we expand into inherited declarations. foreach (var method in registryType.GetMembers(registerMethodName).OfType()) yield return method; + // Concrete registry types can inherit callable implementations from base classes. When the + // registry itself is an interface, BaseType is null and this phase intentionally yields nothing. for (var baseType = registryType.BaseType; baseType is not null; baseType = baseType.BaseType) { foreach (var method in baseType.GetMembers(registerMethodName).OfType()) yield return method; } + // Only interface-typed registry members should search interface inheritance. For classes or + // structs this avoids accepting explicit interface implementations that generated code cannot + // call through `this..(...)`. AllInterfaces is already transitive, so the + // same semantic contract may appear multiple times; that is safe because the caller only uses Any(). if (registryType.TypeKind != TypeKind.Interface) yield break;