self contained item in array causes stack overflow
Bug #1051847 reported by
Christian Marrocco
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
NUnit Framework |
In Progress
|
Low
|
Charlie Poole |
Bug Description
[Bug now tracked at https:/
using System.Collections;
using System.
using NUnit.Framework;
[TestFixture]
public class Reproduction {
class SelfContainer : IEnumerable { public IEnumerator GetEnumerator() { yield return this; } }
[Test]
public void SelfContainedIt
var item = new SelfContainer();
var items = new SelfContainer[] { new SelfContainer(), item };
// work around
Assert.
// causes StackOverflowEx
Assert.
}
}
Reproduced in NUnit 2.6.1
See also bug #491300
Changed in nunitv2: | |
assignee: | nobody → Simone Busoli (simone.busoli) |
status: | New → Confirmed |
Changed in nunitv2: | |
importance: | Undecided → Low |
status: | Confirmed → In Progress |
Changed in nunitv2: | |
milestone: | none → 2.6.3 |
Changed in nunitv2: | |
milestone: | 2.6.3 → none |
affects: | nunitv2 → nunit-3.0 |
tags: | added: github |
To post a comment you must log in.
The problem with the code above is not really in the comparison between the two references to item (the variable and the element in the array) but rather with the non-failing comparison between item and the new instance of SelfContainer in position 0 in the array, which causes the stack overflow. That is quite easy to fix, but while working on it and writing some tests I encountered an interesting scenario:
Should array1 and array2 be considered equal?
The first element is definitely equal, it's 1. What about the second element of each of them? They are self references to the arrays, which in turn contain 1 at the first element and another self reference, and so on forever.
We can implement it either way, but I'm not sure what is the "correct" one.