mirror of
https://github.com/SK-la/osu-framework.git
synced 2026-03-15 03:20:30 +00:00
Fix caching recursive interface definitions
This commit is contained in:
@@ -30,6 +30,7 @@ namespace osu.Framework.SourceGeneration.Tests
|
||||
[InlineData("PartialNestedClasses")]
|
||||
[InlineData("NestedCachedClass")]
|
||||
[InlineData("MultipleCachedMember")]
|
||||
[InlineData("CachedInheritedInterface")]
|
||||
public async Task Check(string name) => await RunTest(name).ConfigureAwait(false);
|
||||
|
||||
protected override Task Verify((string filename, string content)[] sources, (string filename, string content)[] generated)
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// <auto-generated/>
|
||||
#nullable enable
|
||||
#pragma warning disable CS4014
|
||||
|
||||
partial class CachedInheritedInterface : osu.Framework.Allocation.ISourceGeneratedDependencyActivator
|
||||
{
|
||||
public override void RegisterForDependencyActivation(osu.Framework.Allocation.IDependencyActivatorRegistry registry)
|
||||
{
|
||||
if (registry.IsRegistered(typeof(CachedInheritedInterface)))
|
||||
return;
|
||||
base.RegisterForDependencyActivation(registry);
|
||||
registry.Register(typeof(CachedInheritedInterface), null, (t, d, i) =>
|
||||
{
|
||||
var dependencies = new osu.Framework.Allocation.DependencyContainer(d);
|
||||
osu.Framework.Utils.SourceGeneratorUtils.CacheDependency(dependencies, typeof(CachedInheritedInterface), t, i, typeof(IInterface1), null, null);
|
||||
osu.Framework.Utils.SourceGeneratorUtils.CacheDependency(dependencies, typeof(CachedInheritedInterface), t, i, typeof(IInterface2), null, null);
|
||||
return dependencies;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
public partial class CachedInheritedInterface : osu.Framework.Graphics.Drawable, IInterface1
|
||||
{
|
||||
}
|
||||
|
||||
[osu.Framework.Allocation.Cached]
|
||||
public interface IInterface1 : IInterface2
|
||||
{
|
||||
}
|
||||
|
||||
[osu.Framework.Allocation.Cached]
|
||||
public interface IInterface2
|
||||
{
|
||||
}
|
||||
@@ -48,9 +48,9 @@ namespace osu.Framework.SourceGeneration
|
||||
}
|
||||
|
||||
// Process any [Cached] attributes on any interface on the class excluding base types.
|
||||
foreach (var iFace in symbol.Interfaces)
|
||||
foreach (var iFace in SyntaxHelpers.GetDeclaredInterfacesOnType(symbol))
|
||||
{
|
||||
// Add an interface entry for all interfaces that have a cached attribute.
|
||||
// Add an entry if this interface has a cached attribute.
|
||||
if (iFace.GetAttributes().Any(attrib => SyntaxHelpers.IsCachedAttribute(attrib.AttributeClass)))
|
||||
addCandidate(context, classSyntax).CachedInterfaces.Add(iFace);
|
||||
}
|
||||
|
||||
@@ -176,5 +176,16 @@ namespace osu.Framework.SourceGeneration
|
||||
|| IsResolvedAttribute(semanticModel, attrib)
|
||||
|| IsCachedAttribute(semanticModel, attrib));
|
||||
}
|
||||
|
||||
public static IEnumerable<ITypeSymbol> GetDeclaredInterfacesOnType(INamedTypeSymbol type)
|
||||
{
|
||||
foreach (var declared in type.Interfaces)
|
||||
{
|
||||
yield return declared;
|
||||
|
||||
foreach (var nested in declared.AllInterfaces)
|
||||
yield return nested;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user