Skip to content

Commit

Permalink
Fix cycle checking...
Browse files Browse the repository at this point in the history
  • Loading branch information
carl-andersson-at-westermo committed Apr 29, 2024
1 parent da17549 commit 78825f4
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions FactoryGenerator/FactoryGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,12 @@ private static void CheckForCycles(ImmutableArray<Injection> dataInjections)
var tree = new Dictionary<INamedTypeSymbol, List<INamedTypeSymbol>>(SymbolEqualityComparer.Default);
foreach (var injection in dataInjections)
{
var node = new List<INamedTypeSymbol>();
foreach (var iface in injection.Interfaces)
{
if (!tree.ContainsKey(iface))
{
tree[iface] = new List<INamedTypeSymbol>();
tree[iface] = node;
}
}

Expand All @@ -478,10 +479,7 @@ private static void CheckForCycles(ImmutableArray<Injection> dataInjections)
named = (INamedTypeSymbol) named.TypeArguments[0];
}

foreach (var iface in injection.Interfaces)
{
tree[iface].Add(named);
}
node.Add(named);

if (tree.TryGetValue(named, out var list))
{
Expand All @@ -492,18 +490,13 @@ private static void CheckForCycles(ImmutableArray<Injection> dataInjections)
}
}

if (parameter.Type is IArrayTypeSymbol array)
if (parameter.Type is not IArrayTypeSymbol {ElementType: INamedTypeSymbol arrType}) continue;
{
if (array.ElementType is INamedTypeSymbol arrType)
node.Add(arrType);
if (!tree.TryGetValue(arrType, out var list)) continue;
foreach (var iface in injection.Interfaces)
{
tree[injection.Type].Add(arrType);
if (tree.TryGetValue(arrType, out var list))
{
foreach (var iface in injection.Interfaces)
{
if (list.Contains(iface)) throw new InvalidOperationException($"Cyclic Dependency Detected between {injection.Type} and {iface}");
}
}
if (list.Contains(iface)) throw new InvalidOperationException($"Cyclic Dependency Detected between {injection.Type} and {iface}");
}
}
}
Expand Down

0 comments on commit 78825f4

Please sign in to comment.