diff --git a/Robust.Shared/Prototypes/MultiRootInheritanceGraph.cs b/Robust.Shared/Prototypes/MultiRootInheritanceGraph.cs index c7a797dd586..66cdc5d6d2f 100644 --- a/Robust.Shared/Prototypes/MultiRootInheritanceGraph.cs +++ b/Robust.Shared/Prototypes/MultiRootInheritanceGraph.cs @@ -38,6 +38,9 @@ public void Add(T id, params T[] parents) //check for circular inheritance foreach (var parent in parents) { + if (EqualityComparer.Default.Equals(parent, id)) + throw new InvalidOperationException($"Self Inheritance detected for id \"{id}\"!"); + var parentsL1 = GetParents(parent); if(parentsL1 == null) continue; diff --git a/Robust.UnitTesting/Shared/Prototypes/MultiRootGraphTest.cs b/Robust.UnitTesting/Shared/Prototypes/MultiRootGraphTest.cs index a907c1d795d..8344f276ec3 100644 --- a/Robust.UnitTesting/Shared/Prototypes/MultiRootGraphTest.cs +++ b/Robust.UnitTesting/Shared/Prototypes/MultiRootGraphTest.cs @@ -104,4 +104,11 @@ public void CircleCheckTest() Assert.Throws(() => graph.Add(Id3, new[] { Id1 })); } + + [Test] + public void IsOwnParentTest() + { + var graph = new MultiRootInheritanceGraph(); + Assert.Throws(() => graph.Add(Id1, new []{ Id1 })); + } }